Permutation in String | Multiple Approaches | Clean Dry Run | Leetcode 567 | codestorywithMIK

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



Duration: 0:00
8,797 views
446


Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
This is the 27th Video of our Playlist "Sliding Window : Popular Interview Problems" by codestorywithMIK

In this video we will try to solve a classic Sliding Window Problem : Permutation in String | Multiple Approaches | Clean Dry Run | Leetcode 567 | codestorywithMIK

Permutation Video Link -    • Permutations | INTUITIVE | Backtracki...  

I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Also, please note that my Github solution link below contains both C++ as well as JAVA code.

Problem Name : Permutation in String | Multiple Approaches | Clean Dry Run | Leetcode 567 | codestorywithMIK
Company Tags : Amazon, Microsoft
My solutions on Github(C++ & JAVA) - https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Sliding Window/Permutation in String.cpp
Leetcode Link : https://leetcode.com/problems/permutation-in-string


My DP Concepts Playlist :    • Roadmap for DP | How to Start DP ? | ...  
My Graph Concepts Playlist :    • Graph Concepts & Qns - 1 : Graph will...  
My Recursion Concepts Playlist :    • Introduction | Recursion Concepts And...  
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Interview_DS_Algo
Instagram : https://www.instagram.com/codestorywithmik/
Facebook : https://www.facebook.com/people/codestorywithmik/100090524295846/
Twitter : https://twitter.com/CSwithMIK
Subscribe to my channel :    / @codestorywithmik  

╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝

Summary :
Approach 1: Brute Force - TLE

Time Complexity: O(n!⋅m)
Space Complexity: O(n)
Description:
This approach generates all permutations of the string s1 using recursion.
For each permutation, it checks if that permutation exists as a substring in s2 using the find method.
The function recursively swaps characters to create permutations and performs early exits if a valid permutation is found.
Limitations: This method is inefficient for longer strings due to the factorial growth of permutations, leading to a Time Limit Exceeded (TLE) error for larger inputs.
Approach 2: Sorting and Comparing - ACCEPTED

Time Complexity: O((m−n)⋅nlogn)
Space Complexity: O(n)
Description:
This approach first sorts the string s1.
It then iterates through each substring of s2 that has the same length as s1, sorts that substring, and checks if it matches the sorted version of s1.
The comparison relies on the fact that permutations of the same characters will result in identical sorted strings.
Advantages: This method is more efficient than the brute force approach but still incurs a logarithmic cost due to sorting.
Approach 3: Sliding Window - ACCEPTED

Time Complexity: O(m+n)
Space Complexity: O(26) (constant space for frequency counts)
Description:
This efficient approach uses frequency arrays (or vectors) to keep track of the count of characters in s1 and the current window of characters in s2.
As it slides a window of length n over s2, it updates the frequency count dynamically, adding a new character and removing the leftmost character as the window shifts.
It checks for matches between the frequency counts of s1 and the current window in s2.
Advantages: This method is optimal with linear time complexity, making it suitable for large input sizes, and effectively avoids the need for sorting or generating permutations.

✨ Timelines✨
00:00 - Introduction

#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 #hindilearning #helpajobseeker #jobseekers #jobsearchtips #careergoals #careerdevelopment #jobhunt #jobinterview #github #designthinking #learningtogether #growthmindset #digitalcontent #techcontent #socialmediagrowth #contentcreation #instagramreels #videomarketing #codestorywithmik #codestorywithmick #codestorywithmikc #codestorywitmik #codestorywthmik #codstorywithmik #codestorywihmik #codestorywithmiik #codeistorywithmik #codestorywithmk #codestorywitmick #codestorymik #codestorwithmik




Other Videos By codestorywithMIK


2024-10-13Maximal Score After Applying K Operations | Standard Heap Problem | Leetcode 2530 | codestorywithMIK
2024-10-13Smallest Range Covering Elements from K Lists | Multiple Ways | Leetcode 632 | codestorywithMIK
2024-10-11Divide Intervals Into Minimum Number of Groups | Simple Intuition | Leetcode 2406 | codestorywithMIK
2024-10-11The Number of the Smallest Unoccupied Chair | Brute Force | Optimal |Leetcode 1942 |codestorywithMIK
2024-10-10Maximum Width Ramp | Brute Force | Better | Optimal | Leetcode 962 | codestorywithMIK
2024-10-09What motivates me ?
2024-10-08Minimum Add to Make Parentheses Valid | Simple Intuition | Leetcode 921 | codestorywithMIK
2024-10-07Minimum Number of Swaps to Make the String Balanced | Reason | Leetcode 1963 | codestorywithMIK
2024-10-06Minimum String Length After Removing Substrings | 3 Approaches | Leetcode 2696 | codestorywithMIK
2024-10-04Sentence Similarity III | 2 Simple Approaches | Dry Run | Leetcode 1813 | codestorywithMIK
2024-10-03Permutation in String | Multiple Approaches | Clean Dry Run | Leetcode 567 | codestorywithMIK
2024-10-02Make Sum Divisible by P | Simplest Explanation | Full Dry Run | Leetcode 1590 | codestorywithMIK
2024-10-02Divide Players Into Teams of Equal Skill | With Proof | Dry Run | Leetcode 2491 | codestorywithMIK
2024-10-02DSA Shorts with MIK - 6
2024-09-29Design a Stack With Increment Operation | Better Approach | O(1) | Leetcode 1381 | codestorywithMIK
2024-09-29Check If Array Pairs Are Divisible by k | Simplest Explanation | Leetcode 1497 | codestorywithMIK
2024-09-28DSA Shorts with MIK - 5
2024-09-28Design Circular Deque | Simplest Explanation | 2 Ways | Leetcode 641 | codestorywithMIK
2024-09-27Priorities 🥹🥹🥹
2024-09-26My Calendar II | Simplest Explanation | Full Dry Run | Leetcode 731 | codestorywithMIK
2024-09-25My Calendar I | Detailed Approach | Leetcode 729 | codestorywithMIK