Vail Systems Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

Binary value of a given number must have only one 1and that should be at the end of binary .Other digits should be 0.
Ex.2=0010
4=0100
8=1000
16=00010000
32=00100000
64=01000000
...

- Swapnil July 10, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

boolean isAPowerOfTwo(int n) {

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

}

- SK July 10, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Negative numbers are never powers of 2. Would be better as n > 0 && (n & (n-1)) == 0

- 010010.bin July 10, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

good point. fixed.

- SK July 10, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Explain?

- Dax July 11, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I can think of 3 ways:
1. (n & (n-1)) == 0
2. If n is a power of 2 only one bit will be set except the 0th and 31st bit(signed) i am assuming 32 bit int.
3. Keep on dividing by 2, if even times its divided then power of 2.

- Alok July 11, 2015 | 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