My issue
answer varala
My code
def unique_subsets(arr):
def backtrack(start, path):
# Add the current subset to the list of all subsets
all_subsets.append(path[:])
for i in range(start, len(arr)):
# Skip duplicates
if i > start and arr[i] == arr[i - 1]:
continue
# Include the current element
path.append(arr[i])
backtrack(i + 1, path)
# Exclude the current element (backtrack)
path.pop()
arr.sort() # Sort the array to handle duplicates
all_subsets = []
backtrack(0, [])
return all_subsets
def print_subsets(subsets):
for subset in subsets:
print(subset)
if __name__ == "__main__":
n = int(input())
multiset = list(map(int, input().split()))
result = unique_subsets(multiset)
print_subsets(result)
Learning course: Design and Analysis of Algorithms
Problem Link: https://www.codechef.com/learn/course/kl-daa/KLDAA2400I/problems/DSCPPAS267