00:04 Printing all subsets using power set technique 01:37 Power set is the number of subsets 03:16 Using simple Boolean logic to generate power set 04:54 Creating subsets using bit manipulation 06:27 Iterate and generate subsets using bit manipulation. 07:59 Generating power set using bit manipulation 09:34 Generating power set using bit manipulation. 11:14 Discussing space complexity and subset sizes in power set generation.
No one can explain this with that ease..wonderful ππΌππΌππΌππΌ
This problem looks very easy from explanation but after he writes code and mapping back to explanation you will know how tricky it is.... Kudos to you for putting this explanation and solution....
watched it 3-4 times then i get the solution thanks man for explaining so nicely
nums=[1,2,3] length=len(nums) upper=(2**length)-1 sup_set=list() for i in range(upper,-1,-1): ans=list() for j in range(length): mask=1<<j if i&mask : ans.append(nums[j]) sup_set.append(ans) print(sup_set)
c++ code class Solution { public: vector<vector<int>> subsets(vector<int>& nums) { int n = nums.size(); int subsett = 1 << n; vector<vector<int>> ans; for(int num = 0; num < subsett; num++) { vector<int> list; for(int i = 0; i < n; i++) { if(num & (1 << i)) { list.push_back(nums[i]); } } ans.push_back(list); } return ans; } };
Brother i have my placement in 3 months plz continue this playlist
the observation that take set bit of 2^n index in input array as member of a subset is very theoretical & observation intensive and hard to come up with , if we have seen never before, how to deal with it @take U forward
striver its really deep knowledge .its hard to understand but code is simple and couple of lines.However understood boss.
Take a bow πΉ what an explanation 6:16
Love this problem and the way of solving it
public static void main(String[] args) { int[] nums = {1,2,3}; int subsets = 1<<nums.length; ArrayList<ArrayList<Integer>> al = new ArrayList<>(); for(int i=0;i<subsets;i++){ ArrayList<Integer> subal = new ArrayList<>(); for(int j=0;j<nums.length;j++){ if((i&(1<<j))!=0){ subal.add(nums[j]); } } al.add(subal); } System.out.println(al);
broo, i came after that recursion playlist only, there you are telling to watch bit manipulation playlist and here you are telling to watch recursion playlistπ€π€ππ€£, btw you are the best thooo
mjhe to khud pe pura beleive hai ki kv na soch pata mai ye .....mind blowing solution......thanku striver
I got the solution that how ur getting the subsequence but how is that final list ur storing in ans ? What data struc is that ans
If(nums & (1<<i)) kounsa logic lga hai?
the space complexity will be O(2^n) as 2^n is the sum of all the lengths of all the temp lists that will be created
Understood.....Thank You So Much for this wonderful video............ππ»ππ»ππ»ππ»ππ»ππ»
int n = nums.length; List<List<Integer>> ans = new ArrayList<>(); for(int i = 0; i < (1 << n); i++){ int num = i; ArrayList<Integer> ls = new ArrayList<>(); int j = 0; while(num > 0){ if((num & 1) == 1) ls.add(nums[j]); j++; num = num >> 1; } ans.add(ls); } return ans; i did like this. In Java
@sachinvarma9949