#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.
S1 == s2
Iska time complexity O(N) lag jayega...
So, total time complexity is O(N ^ 2)
Poora mood kharab kardiya aapne 😏
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.
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)
@@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 .
@@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.
bruuuuuuuh. its not O(n)
Bhai mat kr mehenat soona aur youtube band krde