Message from C, C++ talks

July 2019

— Its just binary search no?

— Okay

— Yes it is just a simple binary Search .

— What if there's more than 100 elements given?


Yeah...Even the constraints of the problem say 0 < N <= 10^5. And if accordingly I make an array with 100000 size. It says the Time exceeded. I did int arr[100000] but no help.

— You can use std::vector and resize it dynamically

— Help me out I don't know about this std:vector and all.

— Here's documentation
If something is unclear google it, if it doesn't help then ask with details (what exactly is not clear/not working)

Message permanent page

— Use it as vector and if you want to add last item do vector.push_back(item)

— Or just use realloc.

— This. And I would suggest to call reserve as far as it's future size is known.

— I don't know that... Thats cool

— Is it like flag?

— Also, I think there's something with the algorithm itself, because if it's the binary search then why you have the second for loop. It feels like you're doing it linearly. But it looks even stranger

Message permanent page

— While(left<=right){
mid=(left + right)/2;

if(array[mid]==query) {
else if(array[mid]>query) right=mid-1;
else left=mid+1;

} No it was binary search. See.

Message permanent page