Here is the code:-https://ide.codingblocks.com/s/445074, just the implementation of the function that we need to complete, I am not getting the error doing in the code, please specify the mistake. Also please tell will the time complexity would be of O(m+n) where m is the length of string s1 and n is the length of string s2.
Substring Search
hello @Sakshi2004
ur logic looks correct.
the time complexity for ur implementation is O(N*M) becuase in worst the inner loop may run for each i .
Ok but there is one hidden test case that is giving wrong answer. What possible tc that could be?
where u r submitting ?
pls share the question link with me
The question link won’t be of no use because you won’t be able to access it. It’s just that I could share the question only in written.
check now->
Can you please give an example to this, for the line of code you have added there?
s1=abchell
s2=hello
…
…
…
but still it is not working, and also why we are checking like i+s2.length()>s1.length(), instead it could be s1.length()-i < s2.length(), then we can continue or instead break the loop?
that is what i m doing, i have written the break condition (dont match from here) and u have written continue(proceed matching).
The error is that the line 24 of flag needs to be inside for loop because once flag becomes false it is not true.
yeah if u do that and
add this condition in ur code then it should work.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.