Yahoo Interview Question Software Engineer / Developers

  • yahoo-interview-questions
    0
    of 0 votes
    2
    Answers

    Let f(k) = y where k is the y-th number in the increasing sequence of non-negative integers with the
    same number of ones in its binary representation as y, e.g. f(0) = 1, f(1) = 1, f(2) = 2, f(3) = 1,
    f(4) = 3, f(5) = 2, f(6) = 3 and so on. Given k >= 0, compute f(k).

    - gullu on September 12, 2010 Report Duplicate | Flag
    Yahoo Software Engineer / Developer Algorithm



Comment hidden because of low score. Click to expand.
0
of 0 vote

Use recursion.
Base case- f(k): if k has binary digits with all 1s aligned to the right,(and all 0s to the left) return 1;
Recursion- f(k) : return 1 + f(next_lesser_num(k))

next_lesser_num(k) = start from LSD. keep going to the left until you encounter a 0. Now, keep going to the left until to encounter a 1. Flip this 1 to 0 and the zero to the immediate right to 1.

- Dumbo on September 28, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote
- Anonymous on July 26, 2012 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book walking you through every aspect of getting a job at a top tech company, while focuses on software engineering interviews.

Learn More

Videos

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.

Learn More

Resume Review

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.

Learn More

Mock Interviews

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.

Learn More