Permutations II | Two Approaches | Detailed | Recursion Concepts And Questions

Subscribers:
92,300
Published on ● Video Link: https://www.youtube.com/watch?v=Vd2YizhbN74



Duration: 40:10
660 views
47


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




Other Videos By codestorywithMIK


2024-03-04Stay tuned - Life Changing Moment
2024-03-04Largest Number formed from an Array | Largest Number | Comparators Application | Leetcode 179
2024-03-02Remove Nth Node From End of List | 1 Pass | 2 Pass | Leetcode 19
2024-03-01Just don't give up. #codestorywithmik
2024-03-01Squares of a Sorted Array | 2 Approaches | Follow Up | Leetcode 977
2024-02-29Maximum Odd Binary Number | 2 Approaches | Leetcode 2864
2024-02-29Comparators in C++ | sort Example | Function Pointer | Functors | Lambda Expressions
2024-02-29Print Longest Common Subsequence | DP On Strings | DP Concepts & Qns-19
2024-02-28Keep moving guys. We are together ๐Ÿ’ช
2024-02-28Even Odd Tree | DFS | BFS | Leetcode 1609
2024-02-28Permutations II | Two Approaches | Detailed | Recursion Concepts And Questions
2024-02-27Find Bottom Left Tree Value | 3 Approaches | Simple Story | Microsoft | Leetcode 513
2024-02-27Power Set | Same as Subsets | Magic Of Recursion | Recursion Concepts And Questions
2024-02-26Diameter of Binary Tree | Simple Story | Amazon | Leetcode 543
2024-02-26Earliest Second to Mark Indices I | Detailed Intuition | Leetcode Weekly Contest 386 | Leetcode 3048
2024-02-25Generate Parentheses | 2 Approaches | Magic Of Recursion | Recursion Concepts And Questions
2024-02-25Greatest Common Divisor Traversal | Why Graph | Why DSU | Google | Leetcode 2709
2024-02-24Find All People With Secret | 4 Approaches | Google | Leetcode 2092
2024-02-23Thank you and Love You All โค๏ธ๐Ÿ™
2024-02-23N-Queens | 2 Approaches | Super Detailed | Magic Of Recursion | Recursion Concepts And Questions
2024-02-21Bitwise AND of Numbers Range | 2 Approaches | Dry Run | Leetcode 201