public void rearrange(string strr)
char[] str = strr.ToCharArray();
int swap = str.Length - 1;
for (int i = 0; i < str.Length - 1; i++)
if (str[i] == str[i + 1] && swap > i)
if (str[i + 1] == str[swap])
while (str[i + 1] != str[swap])
temp = Convert.ToString(str[swap]);
str[i + 1] = Convert.ToChar(temp);
temp = Convert.ToString(str[swap]);
str[i + 1] = Convert.ToChar(temp);
for (int i = 0; i < str.Length - 1; i++)
if (str[i] == str[i + 1])
for (int i = 0; i < str.Length; i++)
Console.WriteLine("Not Possible");
public static void Main()
Program p = new Program();