Find the Index of the First Occurrence in a String | Google, Microsoft | Leetcode 28
This is the 14th Video of our Strings Playlist.
In this video we will try to solve another very good and popular problem "Find the Index of the First Occurrence in a String - Leetcode 28"
Share your learnings on LinkedIn, Twitter (X), Instagram, Facebook(Meta) with the hashtag #codestorywithmik & feel free to tag me.
Problem Name : Find the Index of the First Occurrence in a String
Company Tags : Google, Amazon, Microsoft, Facebook, Qualcomm
My solutions on Github : github.com/MAZHARMIK/Intervie...
Leetcode Link : leetcode.com/problems/find-th...
My DP Concepts Playlist : • Roadmap for DP | How t...
My Graph Concepts Playlist : • Graph Concepts & Qns -...
My Recursion Concepts Playlist : • Introduction | Recursi...
My GitHub Repo for interview preparation : github.com/MAZHARMIK/Intervie...
Subscribe to my channel : / @codestorywithmik
Instagram : / codestorywithmik
Facebook : / 100090524295846
Twitter : / cswithmik
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview #interviewtips
#interviewpreparation #interview_ds_algo #hinglish
Пікірлер: 64
KMP 😇❤️🙏 kzread.info/dash/bejne/o5Wnx9Vmacq1oM4.htmlsi=WDpG81RfsXWdXUX1
@souravjoshi2293
Жыл бұрын
Requested you to add me in the linkedIn group. Please approve. Thanks
@JJ-tp2dd
Жыл бұрын
bhai, it says - post cannot be displayed, on linkedIn
@codestorywithMIK
Жыл бұрын
Hi all, i think, you will have to join the LinkedIn group to see the video. You can search my page on LinkedIn - codestorywithMIK and join. Once I approve, you will be able to see
@codestorywithMIK
Жыл бұрын
Done @Asim Zohr
@VineetKumar-pj1bk
Жыл бұрын
Can you please share the group link?
Thanks, bhai. Below is the JAVA implementation: class Solution { public int strStr(String s1, String s2) { int m = s1.length(); int n = s2.length(); for(int i=0; i
@souravjoshi2293
Жыл бұрын
People like you are superheroes. Thanks a lot for the JAVA version
@ritik7906
3 ай бұрын
class Solution { public int strStr(String haystack, String needle) { if(haystack.contains(needle) ) return haystack.indexOf(needle); return -1; } }
Your voice is good, the audio was clear and bold and you explained so well. Thank you.
@codestorywithMIK
6 ай бұрын
Means a lot 🙏❤️
Amazing👍
Thanks a lot man
Aapke jaisa banna hai , aapki coding journey share karo pls
congratulations on 8k subs. Please try to cover questions from popular SDE sheets that engineering students are following(these days) meanwhile I wish you all the best for your own SDE sheet. I am following two things 1- POTD leetcode 2- a popular SDE sheet I found on the web. For both things, I first search for your solutions.
@codestorywithMIK
10 ай бұрын
Great suggestion! Let me try that soon. Thank you
Thanks Sir ji
1st view
@thegreekgoat98
Жыл бұрын
Toh tereko abb Nobel Prize chaiye kya?
@vaibhavgupta973
Жыл бұрын
@@thegreekgoat98 yes, de sakte ho toh de do
@AnandKumar-kz3ls
Жыл бұрын
@@vaibhavgupta973 dont worry leetcode will give you badge
Ur efforts is really really gold producers love u bhaiya ❤️❤️❤️❤️
@codestorywithMIK
9 ай бұрын
Means a lot to me. Thank you so much 😇🙏❤️
Hello bro! long time no see✌
for(int i=0;i
Well explained!!! Bro when are you uploading KMP and Rabin karp alg videos?
@codestorywithMIK
9 ай бұрын
Thank you so much. I will soon plan those as well once I am back to India ❤️❤️😇😇🙏🙏
@codestorywithMIK
5 ай бұрын
KMP - kzread.info/dash/bejne/o5Wnx9Vmacq1oM4.htmlsi=WDpG81RfsXWdXUX1
Thanks for the explanation Please provide videos of kmp and rabin karp
@codestorywithMIK
5 ай бұрын
KMP 😇❤️🙏 kzread.info/dash/bejne/o5Wnx9Vmacq1oM4.htmlsi=WDpG81RfsXWdXUX1
class Solution { public int strStr(String haystack, String needle) { if(haystack.length()
(Minimum Fuel Cost to Report to the Capital ) Hii sir please make video of above question
Could anyone share brute force approach?
After the first for loop you can add an if condition which will check if first letter of needle is same as current letter of haystack, so that we won't go inside the second for loop, for each character of haystack.
@codestorywithMIK
Жыл бұрын
Yes
This is O(n) solution in java : 0ms runtime class Solution { public int strStr(String haystack, String needle) { int n = haystack.length(); int strLen = needle.length(); for(int i=0; i
@codestorywithMIK
Жыл бұрын
Thanks a lot
vai kmp and rabin karp ki video bnado eagarly waiting for it
@codestorywithMIK
11 ай бұрын
Sure 👌
@codestorywithMIK
5 ай бұрын
KMP 😇❤️🙏 kzread.info/dash/bejne/o5Wnx9Vmacq1oM4.htmlsi=WDpG81RfsXWdXUX1
12:14 agar dekha jaye to udhar se hi i return krega ....lekin internally kya loop chalega return ke bad v ?
@codestorywithMIK
Жыл бұрын
No. If return is called, then no loop runs further.
@ezcoding69
Жыл бұрын
@@codestorywithMIK ok fir leetcode wale case me wo return kr jayega jidhar S2 'code' tha ....and suppose our S2 is different like ' cody' fir wo condition is testcase me apply hoga .....am I right ?
this is also fine right ? code : class Solution { public: int strStr(string haystack, string needle) { int n=needle.length(); int i=0; int j=0; while(i
Sir please make a video on rabin karp algorithm please sir 😭
@codestorywithMIK
11 ай бұрын
Very soon Noted
@ektuhaso
11 ай бұрын
@@codestorywithMIK tysm sir
@ektuhaso
11 ай бұрын
@@codestorywithMIK sir please make kmp video once more for the coding part please sir as I unable to convert the logic of kmp into code
@codestorywithMIK
11 ай бұрын
I will start a string playlist where I will cover these algo again fresh
@ektuhaso
11 ай бұрын
Thank you so much sir
What is the complexity if we use while loop.. int strStr(string haystack, string needle) { int m = haystack.length(); int n = needle.length(); int count = 0; int i= 0 , j=0; while(i
@sarathkumardunga5240
Жыл бұрын
same TC i.e, O(m*n) Coz in one IF condition u are increasing 'j' and in the ELSE condition u are increasing 'i'.. There is nothing like u are increasing i and j at the same time for every iteration.
@arunsharma4792
Жыл бұрын
@@sarathkumardunga5240 If i have increase i in first iteration and j in second iteration then what will the time complexity?
@sarathkumardunga5240
Жыл бұрын
@@arunsharma4792 In the worst case, for every increment of 'i' u might end up increasing 'j' to 'n-1' characters and last char of j might not match with haystack.So u are resetting j to 0. So u end up time complexity of O(m*n)
Bhai can you tell me complexity of this code pleaseee class Solution { public int strStr(String haystack, String needle) { String match = needle; String ans = ""; int j=0; int i=0; while(j ans += haystack.charAt(j); if(j-i+1 else if(match.equals(ans)){ return i; } else{ ans = ans.substring(1); i++; j++; } } return -1; } }
@codestorywithMIK
Жыл бұрын
while loop take O(m) And match.equals(ans) will take O(n) So it will be O(m*n)
@yashgarg3027
Жыл бұрын
@@codestorywithMIK so it is better than O(n2) ??
@codestorywithMIK
Жыл бұрын
No. It’s equivalent to O(n^2) only Because if m is eqal to n Then O(m*n) = O(n*n) = O(n^2)