@bittu : for that array should be short...
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com.
Input a number and then find the next higher number
such that for both the number (inputted and the next higher
number)
in binary representation contains equal number os ones.
Example:
Input:3(0011)
Ouput:5(0101)
--
Siddharth Srivastava
When you have learned to snatch
how to do that in O(|s|^2)?
2010/11/16 anoop chaurasiya anoopchaurasi...@gmail.com
will O(|s|^2) dp workor u need something more efficient than that
On Tue, Nov 16, 2010 at 1:51 PM, lichenga2404 lichenga2...@gmail.comwrote:
A palindrome is a string which is identical to itself in
@Siddharth: Try this (nnwtsnoob = next number with the same number
of one bits):
unsigned nnwtsnoob(unsigned x)
{
return (x+(x(-x)))|(((x^(x+(x(-x2)/(x(-x)));
}
For the explanation/justification, see
http://groups.google.com/group/programming-puzzles/msg/3a05b3c8b4042d5b.
Dave
On Nov
the idea for O(|S|^2) is as follows
Let string be s[1..n]
p[i][j]=1 if s[i...j] is a palindrome
p[i][j]=0 otherwise.
we can precalculate table p[i][j] as follows..in O(|s|^2)
p[i][i]= 1
p[i][i+1]=1 if s[i]==s[i+1], 0 otherwise
for all others..
p[i][j]= (s[i]==s[j] p[i+1][j-1]==1).
now let