Subsets
Practice this coding question on Coding Gurukul.
Problem statement
A workshop planner has several distinct equipment labels and wants a catalog of every possible kit. A kit can contain any selection of the labels, including no equipment. Choosing a label twice is not allowed, and choosing the same labels in another order does not create a new kit. Your task Generate every subset of the given distinct integers exactly once. To make the catalog deterministic, sort the values inside each subset increasingly, then sort the subsets in numeric lexicographic order. Compare the first unequal numbers; if one list is a prefix of another, the shorter list comes first. The empty subset comes before all others and is written EMPTY. Print the number of subsets first, followed by one subset per line. The original input order must not affect the catalog. Negative labels and zero are valid. Worked example For labels [3, 1], the four catalog entries are EMPTY, 1, 1 3, and 3. The entry 1 precedes 1 3 because it is a shorter prefix. Both labels appear together in only one subset.
Input format
First line: n. Second line: n distinct integers.
Output format
Print the subset count, then one subset per line in numeric lexicographic order; use EMPTY for the empty subset.
Constraints
1 <= n <= 10; -10 <= each value <= 10; values are distinct.
Sample input
2 3 1
Sample output
4 EMPTY 1 1 3 3
Sign in to run or submit a solution in C++, Java or Python.