Check if "listen" and "silent" are anagrams.
Ready — edit the code above and click Run.
using System;
using System.Linq;
class Program
{
static void Main()
{
string a = "listen", b = "silent";
bool ok = a.OrderBy(c => c).SequenceEqual(b.OrderBy(c => c));
Console.WriteLine(ok ? "Anagram" : "Not Anagram");
}
}
Try solving on your own first, then reveal the official answer.
Sort both strings and compare. Interview follow-up: count array of 26 letters for O(n).