Two Billion Plus One
You are binary searching on the answer. The answer can be as large as , so you write:
int lo = 1, hi = 2000000000;
while (lo < hi) {
int mid = (lo + hi) / 2;
if (feasible(mid)) hi = mid;
else lo = mid + 1;
}
feasible is correct and hi fits in an int (). Where does this break?
Sign in to answer questions and track your progress
Sign In