Solved this problem in just three lines

#1

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

#2

Question ke purpose ki MCD

#3

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.

#4

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.

#5

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

#6

RIP binary search,LMAO python fanboizzz

#7

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

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

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

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

#12

Bhai @charu-24 tu naa bahutt bada ganu 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