#17 Longest Prefix Suffix | Data Structures and Algorithms Interview question | String #2

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ส.ค. 2024
  • In this video, we will see how to solve the above question asked in many companies interviews.
    Data Structures and Algorithms Interview question playlist:
    • Data Structures and Al...
    You can practise those questions from here: practice.geeks...
    And if this link doesn't work just google "question_name gfg practice".
    Also if you have any doubts, pls mention them in the comment box.

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

  • @venkatyuva6594
    @venkatyuva6594 2 หลายเดือนก่อน +1

    S1 == s2
    Iska time complexity O(N) lag jayega...
    So, total time complexity is O(N ^ 2)

  • @user-kw3ov8re2h
    @user-kw3ov8re2h ปีที่แล้ว +5

    Poora mood kharab kardiya aapne 😏

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

    DUDE you are checking that s1 and s2 are equal or not , inside a loop. So how can this be done in O(n) time complexity.

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

      operation like insertion, comparison in if statement, etc has constant time i., O(1).
      And as there are n loop so n*1, which is equal to n. So it is O(n)

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

      @@bharathchoudhary4420 comparison of numbers take constant time, but comparison of string doesn't take constant time i guess ..... As there we need to check all the characters one by one .

    • @bharathchoudhary4420
      @bharathchoudhary4420  ปีที่แล้ว +3

      @@heisenberg3488 yes, I missed that. Worst case time complexity for string comparison is O(min(s1,s2)).
      String comparisons typically do a linear scan of the characters, returning false at the first index where characters do not match.
      Thanks for bringing that up, I will comment O(n) approach soon.
      Feel free to add approaches if you have any.

  • @KarthikKarthik-el5hh
    @KarthikKarthik-el5hh 7 หลายเดือนก่อน

    bruuuuuuuh. its not O(n)

  • @bipinsingh1490
    @bipinsingh1490 22 วันที่ผ่านมา

    Bhai mat kr mehenat soona aur youtube band krde