Medium csharp

Anagram check

Problem

Check if "listen" and "silent" are anagrams.

Hints
  • Sort characters of both strings and compare.

Your practice code

Ready — edit the code above and click Run.

Solution

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.

Explanation

Sort both strings and compare. Interview follow-up: count array of 26 letters for O(n).

Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details