Code Lab

Mode entretien. Minuteur de 10 min, sans indices ni autocomplétion

Anagram check

MoyenStrings10 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.

Exemples

isAnagram('Listen', 'Silent')

Renvoie true

isAnagram('dormitory', 'dirty room')

Renvoie true

isAnagram('aab', 'abb')

Renvoie false

Source

Chargement de l'éditeur...
  1. EntréeisAnagram('Listen', 'Silent')
    Attendutrue
  2. EntréeisAnagram('dormitory', 'dirty room')
    Attendutrue
  3. EntréeisAnagram('aab', 'abb')
    Attendufalse

Les tests cachés se lancent à la soumission