Mid From PDF Coding Scenarios C# Coding Interview

Check if two strings are anagrams?

Logic

  • Same length
  • Same character frequency

bool IsAnagram(string s1, string s2)

{
if (s1.Length != s2.Length) return false;
int[] count = new int[256];
foreach (char c in s1) count[c]++;
foreach (char c in s2) count[c]--;
foreach (int i in count)
if (i != 0) return false;
return true;
}

More from C# Programming Tutorial

All questions for this course
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