Q1 is very well answered by Sunny but looks like Q2 is still open.
IMHO, juver++ soln on Q2 doesn't look correct to me (OR I didn't
understand the problem).
if given no is N=2 (010), then next smallest no N+1 = 3 (011) is not
the right answer as it has TWO 1's.
I guess, for N=2 (010), next smallest answer having same no of 1's
will be: 4 (100).
I guess following sud work:

Next Smallest:
1. Find the rightmost 1
2. Find the 1st (rightmost) ZERO (0), in the left of above 1
3. Swap above two
e.g.
N=10(1010), Next smallest: 12(1100)
N=3(011), Next smallest: 6(110)

Next Largest:(having binary no represented in 32 bit)
1. Finf the rightmost 1
2. Find the leftmost ZERO
3. Swap these two

On Jan 17, 7:17 pm, juver++ <avpostni...@gmail.com> wrote:
> @Sunny Good!

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to