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

  • @codestorywithMIK
    @codestorywithMIK Жыл бұрын

    KMP 😇❤️🙏 kzread.info/dash/bejne/o5Wnx9Vmacq1oM4.htmlsi=WDpG81RfsXWdXUX1

  • @souravjoshi2293

    @souravjoshi2293

    Жыл бұрын

    Requested you to add me in the linkedIn group. Please approve. Thanks

  • @JJ-tp2dd

    @JJ-tp2dd

    Жыл бұрын

    bhai, it says - post cannot be displayed, on linkedIn

  • @codestorywithMIK

    @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

    @codestorywithMIK

    Жыл бұрын

    Done @Asim Zohr

  • @VineetKumar-pj1bk

    @VineetKumar-pj1bk

    Жыл бұрын

    Can you please share the group link?

  • @JJ-tp2dd
    @JJ-tp2dd Жыл бұрын

    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

    @souravjoshi2293

    Жыл бұрын

    People like you are superheroes. Thanks a lot for the JAVA version

  • @ritik7906

    @ritik7906

    3 ай бұрын

    class Solution { public int strStr(String haystack, String needle) { if(haystack.contains(needle) ) return haystack.indexOf(needle); return -1; } }

  • @aryansinha1818
    @aryansinha18186 ай бұрын

    Your voice is good, the audio was clear and bold and you explained so well. Thank you.

  • @codestorywithMIK

    @codestorywithMIK

    6 ай бұрын

    Means a lot 🙏❤️

  • @hameedmulani21
    @hameedmulani21 Жыл бұрын

    Amazing👍

  • @souravjoshi2293
    @souravjoshi2293 Жыл бұрын

    Thanks a lot man

  • @prathamtetgure2963
    @prathamtetgure2963 Жыл бұрын

    Aapke jaisa banna hai , aapki coding journey share karo pls

  • @taneyasoni
    @taneyasoni10 ай бұрын

    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

    @codestorywithMIK

    10 ай бұрын

    Great suggestion! Let me try that soon. Thank you

  • @ezcoding69
    @ezcoding69 Жыл бұрын

    Thanks Sir ji

  • @vaibhavgupta973
    @vaibhavgupta973 Жыл бұрын

    1st view

  • @thegreekgoat98

    @thegreekgoat98

    Жыл бұрын

    Toh tereko abb Nobel Prize chaiye kya?

  • @vaibhavgupta973

    @vaibhavgupta973

    Жыл бұрын

    @@thegreekgoat98 yes, de sakte ho toh de do

  • @AnandKumar-kz3ls

    @AnandKumar-kz3ls

    Жыл бұрын

    @@vaibhavgupta973 dont worry leetcode will give you badge

  • @HealthyOm
    @HealthyOm9 ай бұрын

    Ur efforts is really really gold producers love u bhaiya ❤️❤️❤️❤️

  • @codestorywithMIK

    @codestorywithMIK

    9 ай бұрын

    Means a lot to me. Thank you so much 😇🙏❤️

  • @piyushacharya7696
    @piyushacharya7696 Жыл бұрын

    Hello bro! long time no see✌

  • @naveenrajput5315
    @naveenrajput53152 ай бұрын

    for(int i=0;i

  • @siddharthsinghbhadoria3579
    @siddharthsinghbhadoria35799 ай бұрын

    Well explained!!! Bro when are you uploading KMP and Rabin karp alg videos?

  • @codestorywithMIK

    @codestorywithMIK

    9 ай бұрын

    Thank you so much. I will soon plan those as well once I am back to India ❤️❤️😇😇🙏🙏

  • @codestorywithMIK

    @codestorywithMIK

    5 ай бұрын

    KMP - kzread.info/dash/bejne/o5Wnx9Vmacq1oM4.htmlsi=WDpG81RfsXWdXUX1

  • @arunsharma4792
    @arunsharma4792 Жыл бұрын

    Thanks for the explanation Please provide videos of kmp and rabin karp

  • @codestorywithMIK

    @codestorywithMIK

    5 ай бұрын

    KMP 😇❤️🙏 kzread.info/dash/bejne/o5Wnx9Vmacq1oM4.htmlsi=WDpG81RfsXWdXUX1

  • @yuvrajbhardawaj2045
    @yuvrajbhardawaj20455 ай бұрын

    class Solution { public int strStr(String haystack, String needle) { if(haystack.length()

  • @rohitsingh2178
    @rohitsingh2178 Жыл бұрын

    (Minimum Fuel Cost to Report to the Capital ) Hii sir please make video of above question

  • @11csepratikshaargulewar71
    @11csepratikshaargulewar71Ай бұрын

    Could anyone share brute force approach?

  • @itspravas
    @itspravas Жыл бұрын

    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

    @codestorywithMIK

    Жыл бұрын

    Yes

  • @harsh.jain22
    @harsh.jain22 Жыл бұрын

    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

    @codestorywithMIK

    Жыл бұрын

    Thanks a lot

  • @samir3442
    @samir344211 ай бұрын

    vai kmp and rabin karp ki video bnado eagarly waiting for it

  • @codestorywithMIK

    @codestorywithMIK

    11 ай бұрын

    Sure 👌

  • @codestorywithMIK

    @codestorywithMIK

    5 ай бұрын

    KMP 😇❤️🙏 kzread.info/dash/bejne/o5Wnx9Vmacq1oM4.htmlsi=WDpG81RfsXWdXUX1

  • @ezcoding69
    @ezcoding69 Жыл бұрын

    12:14 agar dekha jaye to udhar se hi i return krega ....lekin internally kya loop chalega return ke bad v ?

  • @codestorywithMIK

    @codestorywithMIK

    Жыл бұрын

    No. If return is called, then no loop runs further.

  • @ezcoding69

    @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 ?

  • @vishalplayzz2580
    @vishalplayzz2580 Жыл бұрын

    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

  • @ektuhaso
    @ektuhaso11 ай бұрын

    Sir please make a video on rabin karp algorithm please sir 😭

  • @codestorywithMIK

    @codestorywithMIK

    11 ай бұрын

    Very soon Noted

  • @ektuhaso

    @ektuhaso

    11 ай бұрын

    @@codestorywithMIK tysm sir

  • @ektuhaso

    @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

    @codestorywithMIK

    11 ай бұрын

    I will start a string playlist where I will cover these algo again fresh

  • @ektuhaso

    @ektuhaso

    11 ай бұрын

    Thank you so much sir

  • @arunsharma4792
    @arunsharma4792 Жыл бұрын

    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

    @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

    @arunsharma4792

    Жыл бұрын

    @@sarathkumardunga5240 If i have increase i in first iteration and j in second iteration then what will the time complexity?

  • @sarathkumardunga5240

    @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)

  • @yashgarg3027
    @yashgarg3027 Жыл бұрын

    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

    @codestorywithMIK

    Жыл бұрын

    while loop take O(m) And match.equals(ans) will take O(n) So it will be O(m*n)

  • @yashgarg3027

    @yashgarg3027

    Жыл бұрын

    @@codestorywithMIK so it is better than O(n2) ??

  • @codestorywithMIK

    @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)