Code Lab

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 letters can be used only once: 'apple' has one e, 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 word can always be made.
  • Return a boolean: true or false.

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

Fonte

Carregando o editor...
  1. EntradacanBuildWord('listen', 'silent')
    Esperadotrue
  2. EntradacanBuildWord('cat', 'dog')
    Esperadofalse
  3. EntradacanBuildWord('abc', '')
    Esperadotrue

Os testes ocultos rodam no envio