def search(self, A, B):

if B not in A:

return -1

else:

return A.index(B)

# Solved this problem in just three lines

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.

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

**j8efdjazma**#8

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)

**ChetanZero**#9

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))

**j8efdjazma**#10

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)

**qirs7jkjog**#12

Bhai @charu-24 tu naa bahutt bada gan*u hai . no doubt.
Chu*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