What if we want the index of all the occurences of 40?

@seemantanishth
I don’t know why you can’t understand
Since we need to print all indices anyway
If you just find first index that is enough
You don’t need two function calls

And by your logic since overall complexity is not affected because its log(n) why not make 2 more frivolous binary search calls ?

Technical, you can do that, it won’t effect the ‘complexity’
As I mentioned, complexities don’t take into account the printing of the solution, just the steps to reach to it. It’s like I’m beating around the Bush, for large inpurs even 1000logn is still better than O(n)

@seemantanishth
You still can’t see
My approach works in logn
Your approach works in 2*logn with 2nd begin the unnecessary function call

It does not work in logn, it works in 0(n)
Please study the complexities
Nonetheless, I’m not gonna reply anymore
@subham221 if your doubt was cleared, please mark it as resolved