Code Lab

Modo entrevista. Cronômetro de 10 min, sem dicas e sem autocompletar

Anagram check

MédiaStrings10 min

Write a function isAnagram(a, b) that returns true when the string b is an anagram of a: it has exactly the same characters, the same number of times each, in any order. Otherwise return false.

  • Letter case does not matter: 'Listen' and 'Silent' are anagrams.
  • Spaces do not count: 'dormitory' and 'dirty room' are anagrams.
  • Every other character counts: digits, punctuation, letters such as é, and emoji.
  • The number of times matters: 'aab' and 'abb' are not anagrams, even though they use the same letters.
  • Two empty strings are anagrams.
  • A string can be long, up to 300 000 characters. Your code must finish in time.

Exemplos

isAnagram('Listen', 'Silent')

Retorna true

isAnagram('dormitory', 'dirty room')

Retorna true

isAnagram('aab', 'abb')

Retorna false

Fonte

Carregando o editor...
  1. EntradaisAnagram('Listen', 'Silent')
    Esperadotrue
  2. EntradaisAnagram('dormitory', 'dirty room')
    Esperadotrue
  3. EntradaisAnagram('aab', 'abb')
    Esperadofalse

Os testes ocultos rodam no envio