Mode entretien. Minuteur de 10 min, sans indices ni autocomplétion
Duplicate letters in a string
MoyenMap and Set10 min
Write a function findDuplicateLetters(text) that finds the duplicate letters in text: the letters that occur more than once.
- Return an array of letters in lower case.
- Case does not matter (case insensitive):
Aandaare the same letter, so'Aa'gives['a']. - Only the Latin letters
a-zcount. Digits, spaces, other characters and letters outsidea-z(likeé) are ignored. - Every duplicate letter is in the result once, even if it occurs three or more times.
- Order: by the first occurrence of the letter in
text.'Programming'gives['r', 'g', 'm'], not['r', 'm', 'g']. - If there are no duplicate letters (also for an empty string), return an empty array.
A simple way is a counter for every letter in a Map, then a second pass over it.
Exemples
findDuplicateLetters('Programming')Renvoie [ 'r', 'g', 'm' ]
findDuplicateLetters('Hello World')Renvoie [ 'l', 'o' ]
findDuplicateLetters('abc')Renvoie []
Posé chez Amazon · Source
Chargement de l'éditeur...
- Entrée
findDuplicateLetters('Programming')Attendu[ 'r', 'g', 'm' ] - Entrée
findDuplicateLetters('Hello World')Attendu[ 'l', 'o' ] - Entrée
findDuplicateLetters('abc')Attendu[]
Les tests cachés se lancent à la soumission