Modo entrevista. Cronômetro de 10 min, sem dicas e sem autocompletar
Remove the spaces and sort
MédiaStrings10 min
Write a function sortCharacters(text) that removes all whitespace from the string text and returns the other characters sorted.
texthas only ASCII characters: letters, digits, punctuation and whitespace.- Whitespace is a space, a tab
\tand a line break\nor\r. All of it goes, not only spaces. - Each character is sorted by its character code, from small to large. This is the order of sort without a compare function. For example,
!and,come before the digits, the digits come before the capital letters, and the capital letters come before the small letters. So'Z'comes before'a'. - Repeated characters stay:
'banana'gives'aaabnn'. - Return a string. An empty string or a string of only whitespace gives
''.
Exemplos
sortCharacters('My Name is Nikhil')Retorna 'MNNaehiiiklmsy'
sortCharacters('Zebra 123')Retorna '123Zaber'
Cobrada em Cognizant · Fonte
Carregando o editor...
- Entrada
sortCharacters('My Name is Nikhil')Esperado'MNNaehiiiklmsy' - Entrada
sortCharacters('b a')Esperado'ab'
Os testes ocultos rodam no envio