Solved this problem in just three lines


def search(self, A, B):
if B not in A:
return -1
return A.index(B)


Question ke purpose ki MCD :slight_smile:


not in -> Uses O(N) complexity. The goal of binary search is to reduce the complexity in the first place, by doing the above you gained points but lost the thought process and gist of the question.


You can’t solve this with O(log n) complexity, because there are duplicates in the test cases when you submit your solution, which in worst case scenario will be O(n). That’s why this case would be accepted and make sense. But it’s mostly because of the poorly managed description and/or test cases by InterviewBit. It’s sad I spent so much time to realize it.


It’s mentioned that there are no duplicates in the array. So the O(LogN) solution would work.


RIP binary search,LMAO python fanboizzz


You can solve the question even if it has duplicates in O(logn) soln.
Just search for it on google and you’ll find many articles


You can’t. In the worst case it will be O(N) Time. But it’s extreme worst case only. On average it will be O(logN)


Could you tell me how in worst case it will take TC:O(N), when its already mentioned no duplicates would be provided. I solved it in O(log(N))


I meant O(N) when there are duplicates. That was reply to shivamvegata who said even if there are duplicates we can solve in O(logn)


Bhai @charu-24 tu naa bahutt bada ganu hai . no doubt.
iyae complexity naam ki bhi koi chij hoti hai.
yeah pae main 40 min sae binary search ko lagaae jaa raha hu
Tu salae aisa comment karkae aur jhatt kue jala raha