78. Subsets | backtracking | leetcode daily challenge | DSA | Hindi
Vložit
- čas přidán 19. 05. 2024
- Problem Name:
78. Subsets
Problem Statement:
Given an integer array nums of unique elements, return all possible
subsets
(the power set).
The solution set must not contain duplicate subsets. Return the solution in any order.
Problem link:
leetcode.com/problems/subsets...
Java Plus DSA Placement Course Playlist:
• Java and DSA Course Pl...
Java Plus DSA Sheet:
docs.google.com/spreadsheets/...
Notes:
github.com/Tiwarishashwat/Jav...
Telegram Link:
shashwattiwari.page.link/tele...
Ultimate Recursion Series Playlist:
• Recursion and Backtrac...
Instagram Handle: (@shashwat_tiwari_st)
shashwattiwari.page.link/shas...
Samsung Interview Experience:
• I cracked Samsung | SR...
Company Tags:
Facebook | Amazon | Microsoft | Netflix | Google | LinkedIn | Pega Systems | VMware | Adobe | Samsung
Timestamp:
0:00 - Introduction
#ShashwatTiwari #coding #problemsolving
SUPERB EXPLANATION BROTHER:
Here is the equivalent Python code:
def subsets(nums: List[int]) -> List[List[int]]:
result = []
def backtrack(sublist, index):
# If current index is equal to length of actual array
# then we need to add sublit into result and return
if index == len(nums):
# Need to append copy of sublist otherwise it copies reference
# which can be modified further while doing sublist.pop()
result.append(sublist.copy())
return
# Pick: Add current index element to subarray
sublist.append(nums[index])
backtrack(sublist, index + 1)
# Delete last picked element to go to previous state
sublist.pop()
# No-Pick: Call backtrack for next index
backtrack(sublist, index + 1)
Thanks 😊.
bhaiya dsa ke greedy algo ka lec kab aayega
I have solved it using bit manipulation
share code here
@@Harsh-jc2bz
class Solution {
public List subsets(int[] nums) {
List list=new ArrayList();
int n=(int)Math.pow(2,nums.length)-1;
for(int i=0;ij)&1)==1){
temp.add(nums[j]);
}
}
list.add(temp);
}
return list;
}
}
Nice 💯🔥