Modo entrevista. Cronômetro de 10 min, sem dicas e sem autocompletar
Build a word from letters
MédiaStrings10 min
Write a function canBuildWord(letters, word) that checks if you can make word from the letters of letters.
- Both arguments are strings of Latin letters. Either of them can be empty.
- Every character of
letterscan be used only once:'apple'has onee, so it cannot make'peel'. - Case does not matter:
'A'and'a'are the same letter. - Letters that are left over are fine.
- An empty
wordcan always be made. - Return a boolean:
trueorfalse.
Tip: a counter in a Map tells you how many times each letter is still free.
Exemplos
canBuildWord('listen', 'silent')Retorna true
canBuildWord('apple', 'peel')Retorna false
canBuildWord('Aab', 'aAB')Retorna true
Carregando o editor...
- Entrada
canBuildWord('listen', 'silent')Esperadotrue - Entrada
canBuildWord('cat', 'dog')Esperadofalse - Entrada
canBuildWord('abc', '')Esperadotrue
Os testes ocultos rodam no envio