Amazon Interview Question for Software Engineer / Developers






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

return n&(n-1)==0;

- Anonymous February 04, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

ur soln. does not work for number 6.

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

this solution works perfectly. n&(n-1) sets the LSB to 0.
By checking n&(n-1)==0, you are checking there is only 1 bit turned ON which is the condition for power of 2.
thanks

- e=mc2 March 10, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

nice soln

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

Elegant! Bravo!

- mathytime September 22, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

well, i dont think so that 6 is a power of 2!

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

The first solution perfectly works. 6 & 5 == 4 != 0 hence false. so 6 is not a power of 2.

- Ranga February 26, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This assumes that n=0 is considered a power of 2.

- Anonymous April 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

if (num & 1) != num it is a power of 2

- limca500ml January 25, 2013 | 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