Yahoo Interview Question for Software Engineer / Developers






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

initialize sum=0;
for the first and second bit check if they are set and add 1 to sum if first bits is set and add 2 to sum if second bit is set. then proceed on remaining stream from 3rd bit onwards.for every odd bit set add 1 to sum and for evry even bit set substract 1 from sum and meanwhile also make it sure that when sum exceeds 3 den set sum as sum%3.thus at any point of time the value of sum would tell u the divisibily.if sum=0,3 then its divisible else not..

- saumils1987 September 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

excellent man

- Anonymous November 16, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

yoyo thanks buddy....

- saumils1987 November 16, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

great dude

- dinesh February 22, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

great

- bac December 25, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

if the number of 1's in odd position = number of 1's in even position, number is divisible by 3

- Anonymous September 26, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

Using the property(if the number of 1's in odd position = number of 1's in even position, number is divisible by 3) above, maintain 2 counters to count the number of 1s occuring in odd and even positions of the digit. At any point of time, if the counters are equal that number is divisible by 3.

- Murali Mohan September 29, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Check for 21 -> 10101

- S October 08, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How about
N is divisible by 3 if and only if
# of 1's in even position == # of 1's in odd position (mod 3).

In case of 21: 0 == 3 (mod 3)

In fact, using induction you can prove the following:

Given a non-negative number n, let odd(n) be the count of 1's in the odd positions of n's binary representation and even(n) is the count of 1's in even position. Then

odd(n) - even(n) = n (mod 3)

Or, in other words, (odd(n) - even(n)) % 3 == n % 3.

- czpete October 12, 2010 | Flag Reply


Add a Comment
Name:

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

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

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