akaaa
BAN USER
Comments (5)
Reputation 0
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.
Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.
Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.
Basically start from the end to the beginning. Since the api argument is unsigned 16 bit the range is 0 through 65,535 (2^16 - 1). We search from 65535 as below.
- akaaa October 14, 20151. Lower range = 0, higher range 65535 so we search if the (0+65535)/2 value is 0 or not? Basically just call the api with 65535/2 value.
2. If that is 0 it means the amount in the bank is lesser and consequently otherwise.
3. In case of nonzero value we start taking out money 1 by 1.
unit16 withdraw_total(uint16 value){
int lower = 0; int higher = 65535;
while (lower <= higher) {
int pivot = (lower+higher)/2;
if (withdraw(pivot)) {
while (withdraw(1));
} else {
higher = pivot-1;
}
}
}