Minimum Time to Revert Word to Initial State | Part I | Part II | KMP | Leetcode 3029 | 3031

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



Duration: 1:07:22
1,184 views
94


Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
This is the 39th Video of our Playlist "Strings : Popular Interview Problems".
In this video we will try to solve two very good string problems asked in Leetcode Weekly Contest 383 :
Minimum Time to Revert Word to Initial State I (Leetcode 3029)
Minimum Time to Revert Word to Initial State II (Leetcode 3031)

KMP Detailed - https://youtu.be/qases-9gOpk?si=G2XukMW4hRqtU6pr

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 : Minimum Time to Revert Word to Initial State I | Minimum Time to Revert Word to Initial State II | Leetcode 3029 | 3031
Company Tags : Will update soon
My solutions on Github(C++ & JAVA) :
Part I : https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/strings/Minimum%20Time%20to%20Revert%20Word%20to%20Initial%20State%20I.cpp
Part II : https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/strings/Minimum%20Time%20to%20Revert%20Word%20to%20Initial%20State%20II.cpp
Leetcode Link :
Part I : https://leetcode.com/problems/minimum-time-to-revert-word-to-initial-state-i/description/
Part II : https://leetcode.com/problems/minimum-time-to-revert-word-to-initial-state-ii/description/


My Recursion Concepts Playlist : https://www.youtube.com/watch?v=pfb1Zduesi8&list=PLpIkg8OmuX-IBcXsfITH5ql0Lqci1MYPM
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 - 1 Summary : The goal is to determine the minimum number of iterations required to reach the initial state by repeatedly concatenating substrings of length 'k' from the end of the word to the beginning. The method utilizes a helper function 'check' to verify if the substring from index 'i' to 'n' is equal to the substring from index '0' to 'n - i.' The algorithm iterates through the word, incrementing a counter 'count' and updating the index 'i' by 'k' until a match is found, and then returns the final count.

Approach-2 Summary : This method calculates the minimum number of iterations needed to reach the initial state by repeatedly concatenating substrings of length 'k' from the end of the word to the beginning. The algorithm utilizes the Knuth-Morris-Pratt (KMP) algorithm's Longest Prefix Suffix (LPS) function to find the length of the longest proper prefix which is also a suffix. The code initializes an LPS array, finds the maximum LPS value, and then iterates through a loop to determine if a valid substring length 'k' exists based on the LPS array. Finally, the method returns the minimum number of iterations required.


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

✨ 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 #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #2024 #newyear




Other Videos By codestorywithMIK


2024-02-14Subsets | Simple Story To Code | Leetcode 78 | Recursion Concepts And Questions | Video 10
2024-02-13Rearrange Array Elements by Sign | 2 Approaches | Why Order Preserve | Leetcode 2149
2024-02-13Quick Sort | Simple Story | Story To Code | Recursion Concepts And Questions | Video 9
2024-02-12Find First Palindromic String in the Array | Multiple Ways | Leetcode 2108
2024-02-11Cherry Pickup II | 3 Approaches | Super Detailed | Leetcode 1463
2024-02-10Tumlog saath ho. Bas kaafi hai ❤️ 18K family #codestorywithmik
2024-02-09Palindromic Substrings | Blueprint | Palindrome Problems | 4 Approaches | Leetcode 647
2024-02-08Largest Divisible Subset | LIS Variant | DP Concepts & Qns-18 | Leetcode-368
2024-02-08Merge Sort | Simple Story | Story To Code | Recursion Concepts And Questions | Video 8
2024-02-07Perfect Squares | Bottom UP | Made Easy | Google | Leetcode 279
2024-02-07Minimum Time to Revert Word to Initial State | Part I | Part II | KMP | Leetcode 3029 | 3031
2024-02-06Tower Of Hanoi | Simple Story | Story To Code | Recursion Concepts And Questions | Video 7
2024-02-06Count the nodes at distance K from leaf | 2 Approaches | Simple Dry Run | GFG POTD
2024-02-05Tail Recursion | Tail call Optimisation | Examples | Recursion Concepts And Questions | Video 5
2024-02-05Time Complexity | Space Complexity | Examples | Recursion Concepts And Questions | Video 4
2024-02-05Recursion Tree | Call Stack | Recursion Concepts And Questions | Video 3
2024-02-05Recursion Leap Of Faith | Examples | Recursion Concepts And Questions | Video 2
2024-02-05Introduction | Recursion Concepts And Questions | Video 1
2024-02-04First Unique Character in a String | Easy | Leetcode 387
2024-02-03Every trip teaches me something. #codestorywithmik
2024-02-02Partition Array for Maximum Sum | Why DP | Recursion | Memo | Bottom Up | Leetcode 1043