Web applications engineer interview questions shared by candidates
How to discover if the given number is Power of 2 ?
10=2 100=4 1000=8… Caught the thing .. he didn't like my implementation. don't be nervous!
return (( x!=0) && (x & (x -1) == 0)) a number which is power of two will have single 1 in binary representation ex. 16 00010000 x-1 will have pattern 00001111 hence x&(x-1) will always be 0 for power of two numbers. Need to check condition for x!=0 since 0 is not a power of two. Special case to handle.
if you can figure this out inside an hour, congratulations this isnt something that should be in an interview to be honest the level of difficulty of the answer that algo came up with is at the level of an upper division course that has a proof of it written in wikipedia i honestly like the brute force solution
See Interview Questions for Similar Jobs
- Pharmacy Technician
- Social Worker
- Dental Assistant
- Graphic Designer
- Truck Driver
- Pharmaceutical Sales
- Security Guard
- Sales Associate