Message from C, C++ talks

July 2019

— 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.

Message permanent page

— 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
https://en.cppreference.com/w/cpp/container/vector
If something is unclear google it, if it doesn't help then ask with details (what exactly is not clear/not working)

— 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) {
result=mid;
break;
}
else if(array[mid]>query) right=mid-1;
else left=mid+1;

}
cout<<result<<endl;
} No it was binary search. See.

Message permanent page

— This allocates chunk of memory that can hold the asked amount of elements.
So when you do push_back it doesn't call for additional reallocations

Message permanent page

— Yeag

— I know how storing stuff In memory works