LeetCode Entry

242. Valid Anagram

16.12.2023 easy 2023 kotlin

#### Join me on Telegram

242. Valid Anagram easy blog post substack image.png

Join me on Telegram

https://t.me/leetcode_daily_unstoppable/440

Complexity

  • Time complexity: \(O(n)\)

  • Space complexity: \(O(n)\), can also be solved in O(1) by computing the hash

Code


    fun isAnagram(s: String, t: String): Boolean =
      s.groupBy { it } == t.groupBy { it }