Longest Prefix Suffix | Find Longest Prefix which is also Suffix | Coder Army Sheet | GFG| Leetcode

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 ต.ค. 2024

ความคิดเห็น • 23

  • @whysrishti
    @whysrishti 11 หลายเดือนก่อน +1

    Perfectly explained theory!

  • @artandcraftworld38
    @artandcraftworld38 ปีที่แล้ว +4

    very very nice explanation brother shi me pura concept clear ho gya is que. ka !!!!

    • @circleofcoding
      @circleofcoding  ปีที่แล้ว

      Thanks bro. Plzz share this channel among your friends..

  • @Abhishek-ys2io
    @Abhishek-ys2io ปีที่แล้ว +3

    Bro, at 13:54, you explained wrong. 'j' will not shift to '0', j will be equal to lps[j-1]

    • @circleofcoding
      @circleofcoding  ปีที่แล้ว

      Yes, i think i have said it wrong, but in code part, it is right..

  • @wisdomkhan
    @wisdomkhan ปีที่แล้ว +5

    Thank you. KMP bhi samjha dijye.

  • @AmandeepSingh-kr6he
    @AmandeepSingh-kr6he 3 หลายเดือนก่อน

    waah guru kya hi btaya hai yaar maze aagye smj kr, bs last m equation nahi btayi j = lp[j-1].

  • @PriyanshuSharma_1720
    @PriyanshuSharma_1720 ปีที่แล้ว +2

    great bhai
    bs solution dalna bnd mt krna is sheet ke
    ye sheet bhot bdiya hai
    or app bhi bhot ache se explain kr rhe ho sbhi question

    • @circleofcoding
      @circleofcoding  ปีที่แล้ว +1

      Hnn, plzz share this channel among your friends. Thanks in advance.

  • @eeshanagarwal9371
    @eeshanagarwal9371 ปีที่แล้ว +2

    j=0 kyu nhi likh rhe seedha? j= lp[ j-1 ] kyu krna pdra h bhaiya, hr baar j ko 0 ke equal nhi krna padega jab bhi s[i] and s[j] unequal honge?

    • @circleofcoding
      @circleofcoding  ปีที่แล้ว +1

      Har baar 0 se nhi krna hai n, jaha se match hona suru hoga, waha se compare krenge n.. Ekbaar dry run krke dekho dono case ko, tab smjh aayega..

  • @rishabhgupta596
    @rishabhgupta596 ปีที่แล้ว +2

    bro in the else part why you put j=lp[j-1] and not j=0 as we have to start from the beginning

    • @circleofcoding
      @circleofcoding  ปีที่แล้ว +1

      It's the standard way to write it, j=0 is also correct. U can go with either..

    • @swagatochakraborty6043
      @swagatochakraborty6043 ปีที่แล้ว +2

      @@circleofcoding I think writing j = 0 will give error. Try for this string "acccbaaacccbaac". I think you need to write j = lp[j-1] as you need to move to the next part of the already found suffix substring of this array

    • @varshagoyal9574
      @varshagoyal9574 ปีที่แล้ว

      @@swagatochakraborty6043 thankss for clearing this

    • @AmandeepSingh-kr6he
      @AmandeepSingh-kr6he 3 หลายเดือนก่อน

      @@circleofcoding it is not correct in all cases. testcase - acccbaaacccbaac. isko krna glt aayega

  • @saikatghosh9750
    @saikatghosh9750 5 หลายเดือนก่อน

    very good explanation

  • @DK-ox7ze
    @DK-ox7ze ปีที่แล้ว +2

    Great explanation but ek cheez samaj nhi aai. Shouldn't we only consider the suffixes ending at end of the entire string, as we want to find the longest one for the entire string and not a substring?

    • @circleofcoding
      @circleofcoding  ปีที่แล้ว

      Then it will be string itself. Right..

    • @DK-ox7ze
      @DK-ox7ze ปีที่แล้ว

      @@circleofcoding I got that afterwards. But I still don't understand the full KMP algorithm. KMP is more than building the LSP array. It's about finding a string in another string. It will be great if you could do a video on how to use the LSP array to match strings.

    • @circleofcoding
      @circleofcoding  ปีที่แล้ว +1

      @@DK-ox7ze ok, i will make a video if there will be KMP algo.

  • @SarthakInUS
    @SarthakInUS 10 หลายเดือนก่อน

    can you try these test case: it is failing on leetcode q number 1392 acccbaaacccbaac

  • @pksingh-de9cn
    @pksingh-de9cn 3 หลายเดือนก่อน

    jo samjkaye ho and code me difference hai