Reverse Prefix of Word | Detail on reverse Function | Leetcode 2000 | codestorywithMIK
Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
This is the 34th Video of our Playlist "Leetcode Easy" by codestorywithMIK
In this video we will try to solve an easy warm-up problem based on strings : Reverse Prefix of Word | Detail on Library Function | Leetcode 2000 | codestorywithMIK
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 : Reverse Prefix of Word | Detail on Library Function | Leetcode 2000 | codestorywithMIK
Company Tags : Amazon
My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/strings/Easy%20Tagged/Reverse%20Prefix%20of%20Word.cpp
Leetcode Link : https://leetcode.com/problems/reverse-prefix-of-word/
My DP Concepts Playlist : https://youtu.be/7eLMOE1jnls
My Graph Concepts Playlist : https://youtu.be/5JGiZnr6B5w
My Recursion Concepts Playlist : https://www.youtube.com/watch?v=pfb1Zduesi8&list=PLpIkg8OmuX-IBcXsfITH5ql0Lqci1MYPM
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 : https://www.youtube.com/@codestorywithMIK
Summary :
Both approaches aim to reverse the prefix of a string up to a specified character `ch`, but they differ in implementation:
1. **Iterative Approach with Character Array (Simple Loop and Swap):**
- Time Complexity (T.C): \(O(n)\) where \(n\) is the length of the input string `word`. This is because the algorithm iterates through half of the string to perform the swapping.
- Space Complexity (S.C): \(O(1)\). The algorithm performs in-place swapping without any extra space requirements.
- This approach directly manipulates the characters of the string using a simple loop and swap operation until the indices `i` and `j` meet.
2. **Using Library Functions:**
- Time Complexity (T.C): \(O(n)\) where \(n\) is the length of the input string `word`. This is because the `reverse` function reverses a range of elements, which takes linear time.
- Space Complexity (S.C): \(O(1)\). Similar to the first approach, this implementation uses constant extra space.
- This approach utilizes the `reverse` function from the C++ Standard Library algorithm header. It finds the index of the specified character `ch` in the string and then reverses the prefix of the string up to that index using the `reverse` function.
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
✨ 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 #newyear2024