#C13489. Unique Subsets
Unique Subsets
Unique Subsets
Given a list of integers, your task is to generate all possible unique subsets of the list. A subset is a sequence that can be derived from the original list by deleting some (or no) elements without changing the order of the remaining elements. Note that the list might contain duplicate elements, so the solution must ensure that no duplicate subsets are produced.
The solution must use backtracking, and an important observation is that sorting the list first can help avoid duplicates. The time complexity of the solution is \( O(2^n) \) in the worst case.
inputFormat
The input is provided via stdin as a single line containing space-separated integers. If the line is empty, the input list is considered empty.
Examples:
1 2 2
4 4 4 1 4
(empty input corresponds to an empty list)
0
outputFormat
The output should be printed to stdout and must exactly represent the list of unique subsets in the format of a Python-like list literal. Each subset should be a list itself. The order of subsets must follow the order in which they are generated by a backtracking algorithm.
For example, for the input 1 2 2
the expected output is:
[[], [1], [1, 2], [1, 2, 2], [2], [2, 2]]## sample
1 2 2
[[], [1], [1, 2], [1, 2, 2], [2], [2, 2]]