imashutosh51

Find all the subsets of the array

Mar 25th, 2026
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. '''
  2. Here we are taking one subarray and then push all the current elments one by one
  3. '''
  4. class Solution:
  5.     def subsets(self, arr):
  6.         ans=[[]]
  7.         for i in arr:
  8.             new_subset=[]
  9.             for subset in ans:
  10.                 new_subset.append(subset+[i])
  11.             ans=ans+new_subset #'+' basically extend the array
  12.         return ans
  13.        
  14.        
Advertisement
Add Comment
Please, Sign In to add comment