78. Subsets | backtracking | leetcode daily challenge | DSA | Hindi

Sdílet
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​

Komentáře • 7

  • @krishnavishwakarma8637
    @krishnavishwakarma8637 Před měsícem

    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)

  • @RohitKumar-dz8dh
    @RohitKumar-dz8dh Před 2 měsíci +1

    Thanks 😊.

  • @noonecares-786
    @noonecares-786 Před 2 měsíci

    bhaiya dsa ke greedy algo ka lec kab aayega

  • @ravishankar4565
    @ravishankar4565 Před 2 měsíci

    I have solved it using bit manipulation

    • @Harsh-jc2bz
      @Harsh-jc2bz Před 2 měsíci

      share code here

    • @ravishankar4565
      @ravishankar4565 Před 2 měsíci +1

      @@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;
      }
      }

    • @shashwat_tiwari_st
      @shashwat_tiwari_st  Před 2 měsíci

      Nice 💯🔥