What if we create a base 3 number from the given number N and then check if
there is only 1 bit with value 1 and all values should be 0. For example, if
lets say the number is 27. Its base 3 number will be 1 0 0 0, now since there
is only 1 single 1 present in this representation, it is a power
@Gaurav: Even though this is O(log n), it is bound to be slow, since
it would use division and modulus are among the slowest operations on
modern computers, some of which don't even have an integer division
instruction. Here is a revision to my earlier code, for 32-bit
integers. It should be
I think we can also solve this using divide and conquer:
The algorithm is based on the concept of diving the current array into two
parts and then considering if the solution exists, in the first part from lo to
mid and last part from mid+1 to high and the case in which the subarray crosses
Hi
Has anyone appeared for interview in Amazon India? Could anyone please
suggest how the interview pattern is? What are the best URL's where we can
find good material to prepare for the interview? Any sample interview
questions would really help.
Thanks
--
You received this message because