← Coding round practice

Check Two Strings are Anagram

MediumStrings

The problem

Two strings are anagrams if they contain the same characters in any order.

Sample input

listen, silent

Sample output

true
Show the solution · 8 languages
fun isAnagram(a: String, b: String) =
    a.toCharArray().sorted() == b.toCharArray().sorted()

fun main() {
    println(isAnagram("listen", "silent"))
}