Shortest Palindrome | Multiple Ways | KMP Zindabaad | Leetcode 214 | codestorywithMIK

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



Duration: 0:00
10,000 views
438


Whatsapp Community Link : https://www.whatsapp.com/channel/0029...
This is the 43rd Video of our Playlist "Strings : Popular Interview Problems" by codestorywithMIK

KMP By codestorywithMIK -    • Knuth-Morris-Pratt KMP String Matchin...  

In this video we will try to solve a standard Recursion problem : Shortest Palindrome | Multiple Ways | KMP Zindabaad | Leetcode 214 | codestorywithMIK
Detailed and full dry run.

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 : Shortest Palindrome | Multiple Ways | KMP Zindabaad | Leetcode 214 | codestorywithMIK
Company Tags : GOOGLE
My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Intervie...
Leetcode Link : https://leetcode.com/problems/shortes...


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/Intervie...
Instagram :   / codestorywithmik  
Facebook :   / 100090524295846  
Twitter :   / cswithmik  
Subscribe to my channel :    / @codestorywithmik  

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

Summary :
1. Approach: Using Simple Substring Check for Prefix and Suffix

Time Complexity: O(n2)
Space Complexity: O(n)
Description: This approach checks if a prefix of the input string s matches a suffix of the reversed string rev. It iterates through the string s and, for each position i, it compares the substring of s from the beginning with the substring of rev from index i onwards. This comparison checks whether the prefix of s matches the suffix of rev, which would indicate the point at which the palindrome begins. The string is made a palindrome by adding the unmatched portion from the reversed string to the beginning of s.

Advantages: The logic is straightforward and intuitive.
Drawbacks: Since substring comparison takes O(n) time and this is done in a loop O(n) times, the total time complexity is O(n2), making it inefficient for longer strings.
2. Approach: Using LPS (Longest Prefix Suffix) from KMP Algorithm

Time Complexity: O(n)
Space Complexity: O(n)
Description: This approach uses the LPS array, a concept from the KMP (Knuth-Morris-Pratt) string matching algorithm, to efficiently compute the shortest palindrome. The core idea is to concatenate the string s, a separator (-), and the reversed string rev. The LPS array is built for this concatenated string, which helps in identifying the longest prefix of s that is also a suffix. The unmatched part of the reversed string is then added to the beginning of s to make it a palindrome.

Advantages: This approach is optimal with a linear time complexity of O(n), significantly faster than the previous approach.
Drawbacks: Slightly more complex due to the LPS computation, but still relatively efficient in both time and space.

✨ 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 #coding #programming #100daysofcode #developers #techjobs #datastructures #algorithms #webdevelopment #softwareengineering #computerscience #pythoncoding #codinglife #coderlife #javascript #datascience #leetcode #leetcodesolutions #leetcodedailychallenge #codinginterview #interviewprep #technicalinterview #interviewtips #interviewquestions #hinditech #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-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
2024-09-24Sum of Prefix Scores of Strings | Trie | Full Easy Dry Run | Leetcode 2416 | codestorywithMIK
2024-09-23Find the Length of the Longest Common Prefix | 2 Approaches | Leetcode 3043 | codestorywithMIK
2024-09-22Extra Characters in a String | Recursion | Bottom Up | Easy | Leetcode 2707 | codestorywithMIK
2024-09-22K-th Smallest in Lexicographical Order | Super Detailed | Dry Run | Leetcode 440 | codestorywithMIK
2024-09-20Lexicographical Numbers | Simple DFS | Leetcode 386 | codestorywithMIK
2024-09-20Shortest Palindrome | Multiple Ways | KMP Zindabaad | Leetcode 214 | codestorywithMIK
2024-09-18Different Ways to Add Parentheses | Simple Story To Code | Leetcode 241 | codestorywithMIK
2024-09-15Minimum Time Difference | Easy Approach | Detailed | Leetcode 539 | codestorywithMIK
2024-09-15DSA Shorts with MIK - 4
2024-09-15Find the Longest Substring Containing Vowels in Even Counts | Leetcode 1371 | codestorywithMIK
2024-09-14DSA Shorts with MIK - 3
2024-09-13Longest Subarray With Maximum Bitwise AND | Simple Observation | Leetcode 2419 | codestorywithMIK
2024-09-12XOR Queries of a Subarray | Simple Explanation | Leetcode 1310 | codestorywithMIK
2024-09-11Count the Number of Consistent Strings | Using Bit Manipulation | Leetcode 1684 | codestorywithMIK
2024-09-09Insert Greatest Common Divisors in Linked List | 2 Approaches | Leetcode 2807 | codestorywithMIK
2024-09-08Maximum Number of Moves to Kill All Pawns | Step By Step Detailed | Leetcode 3283 | codestorywithMIK