Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures?

// C# program to demonstrate
// ToCharArray() method
using System;
class AllTechnicalFAQs {

// Main Method
public static void Main()
{

String str = Console.ReadLine();

// copy the string str to chars
// character array & it will start
// copy from ‘G’ to ‘s’, i.e.
// beginning to ending of string
char[] chars = str.ToCharArray();

bool isFound = false;

// to display the resulted character array
for (int i = 0; i < chars.Length; i++)
        {
                          for (int j = i+1; i < chars.Length; i++)
                          {
                               if ( chars[I] ==chars[j] )
                                   isFound = true
                          }
                }
              if ( isFound == true )
                       Console.Writeline(“Not Unique”);
             else
                      Console.Writeline(“Unique”);
}
}

Leave a Reply

%d bloggers like this: