Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 13, 2016 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/41e6cbd30228e9ba7204 to your computer and use it in GitHub Desktop.
Save jianminchen/41e6cbd30228e9ba7204 to your computer and use it in GitHub Desktop.
Make It Anagram - Sort two string first, and then, using two pointers - sliding forward
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
class Solution
{
static void Main(String[] args)
{
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */
var str1 = Console.ReadLine().ToCharArray().OrderBy(e => e).ToArray();
var str2 = Console.ReadLine().ToCharArray().OrderBy(e => e).ToArray();
var deletionCount = 0;
int n = 0;
int m = 0;
while (true)
{
if (n >= str1.Length || m >= str2.Length)
break;
if (str1[n] < str2[m])
{
deletionCount++;
n++;
}
else if (str1[n] > str2[m])
{
deletionCount++;
m++;
}
else
{
m++;
n++;
}
}
deletionCount += str2.Length - m + str1.Length - n;
Console.WriteLine(deletionCount);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment