Permutations II | Two Approaches | Detailed | Recursion Concepts And Questions
iPad PDF Notes - https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/iPad%20PDF%20Notes/Recursion%20Concepts%20%26%20Qns%20-%2017.pdf
Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
This is the 16th video of our playlist "Recursion Concepts And Questions". Find the Details below :
We already have studied Permutations - I in my video - https://www.youtube.com/watch?v=T8hqjK94Fig
Video Name : Permutations II | Two Approaches | Recursion Concepts And Questions
Video # : 16
C++/Java Code Link : https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Backtracking/Permutations%20II.cpp
Leetcode Link : https://leetcode.com/problems/permutations-ii/
๐ Unraveling Recursion: A Journey into the Depths of Code
๐ฅ Welcome to the 16th Video of my Recursion Playlist! ๐ In this enlightening video, we will solve another very famous recursion/backtracking problem "Permutations II". We will start with a Simple story as well as Tree Diagram for understanding the problem and then we will be Converting Story to code and writing the recursive code for the problem and also I will also be explaining the Time and Space Complexity of the code ๐. We will be solving it using the same approach as the Permutations I with slight enhancement to handle duplicate cases.
๐ What's Inside?
๐ Simple story understanding with Tree Diagram
๐ Converting Story to code and writing the recursive code for Permutations II problem
๐ Explanation of Time and Space Complexity of the code
๐ฉโ๐ป Who Should Watch?
This playlist is for everyone but best suited for Freshers who are new to Recursion.
๐ Embark on the Recursive Adventure Now!
My DP Concepts Playlist : https://youtu.be/7eLMOE1jnls
My Graph Concepts Playlist : https://youtu.be/5JGiZnr6B5w
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Interview_DS_Algo
Subscribe to my channel : https://www.youtube.com/@codestorywithMIK
Instagram : https://www.instagram.com/codestorywithmik/
Facebook : https://www.facebook.com/people/codestorywithmik/100090524295846/
Twitter : https://twitter.com/CSwithMIK
Approach Summary :
Approach-1 (Using same concept as Permutation-I but keeping count to avoid duplicates):
This approach employs backtracking to generate unique permutations of a given set of numbers. The algorithm maintains a count of the occurrences of each number using an unordered map. It iterates through the map, choosing each number and recursively exploring permutations while updating counts. This ensures duplicates are avoided by keeping track of the count of each number. The time complexity is O(N * N!), where N is the number of elements in the input array, and the space complexity is O(N).
Approach-2 (Using swap technique but avoiding duplicates by using set):
This approach utilizes the swap technique for generating permutations while preventing duplicates using a set to track unique elements. The algorithm recursively swaps elements at different positions and skips duplicates by checking against a set. This ensures that each permutation is unique. The time complexity is O(N * N!) in the worst case, where N is the number of elements in the input array, and the space complexity is O(N). The set is used to store unique elements during the recursive process.
โโโฆโโโฆโโโโฆโโฆโฆโฆโฆโโโโ
โโโฃโโโโโฃโโฃโโฃโโฃโโโฃโโฃ
โ โโโโโโโ โโโโฃโโโโโโโฃ
โโโฉโโโฉโโฉโโฉโโฉโโโฉโโฉโโ
00:00 - Introduction
00:10 - Motivation (Bhashan)
01:45 - Problem Explanation
03:03 - Recall Permutation-I Approach-1
08:00 - Why it fails for Permutations-II
09:49 - Correcting Approach-1 for Permutations-II
15:37 - Coding Approach-1
19:20 - Time & Space Complexity
21:47 - Recall Permutation-I Approach-2
26:26 - Why it fails for Permutations-II
29:52 - Correcting Approach-2 for Permutations-II
35:35 - Coding Approach-2
39:34 - Time & Space Complexity
#codestorywithMIK
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #2024 #newyear #RecursionExplained #CodingJourney #Programming101 #TechTalks #AlgorithmMastery #Recursion #Programming #Algorithm #Code #ComputerScience #SoftwareDevelopment #CodingTips #RecursiveFunctions #TechExplained #ProgrammingConcepts #CodeTutorial #LearnToCode #TechEducation #DeveloperCommunity #RecursiveThinking #ProgrammingLogic #ProblemSolving #AlgorithmDesign #CSEducation