Algorithms : Given two strings , write a method to decide if one is permutation of other

Algorithms : Given two strings , write a method to decide if one is permutation of other 

// C# program to check whether two strings are permutations of each other
using System;

class AllTechnicalFAQs
{

/* function to check whether two strings are permutation of each other */
public bool isPermutation(String str1, String str2)
{
// Get lenghts of both strings
int n1 = str1.Length;
int n2 = str2.Length;

// If length of both strings is not same,
// then they cannot be Permutation
if (n1 != n2)
return false;
char [] ch1 = str1.ToCharArray();
char [] ch2 = str2.ToCharArray();

// Sort both strings
Array.Sort(ch1);
Array.Sort(ch2);

// Compare sorted strings
for (int i = 0; i < n1; i++)
if (ch1[i] != ch2[i])
return false;

return true;
}

/* Main Block*/
public static void Main(String[] args)
{
String str1 = Console.Readline();
String str2 = Console.Readline();
if (isPermutation(str1, str2))
Console.WriteLine(“Yes”);
else
Console.WriteLine(“No”);
}
}

// This code contributed by Rajput-Ji

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

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”);
}
}