Loading...
Loading...
You are given a string sentence made of lowercase words separated by single spaces.
The balance of a word is the absolute difference between its number of consonants and its number of vowels. The vowels are a, e, i, o and u. Every other letter, including y, is a consonant.
Return the words of sentence sorted by balance, smallest first. Words with the same balance are sorted alphabetically.
Note that a word that appears several times in sentence appears that many times in the result.
Input: sentence = "the quick brown fox"
Output: ["fox","quick","the","brown"]
Explanation: "the" has 2 consonants and 1 vowel, so its balance is 1. "quick" (3 and 2) and "fox" (2 and 1) also have balance 1.
"brown" has 4 consonants and 1 vowel, so its balance is 3.
The three words with balance 1 come first, in alphabetical order.
Input: sentence = "aeiou rhythm idea"
Output: ["idea","aeiou","rhythm"]
Explanation: "idea" has 1 consonant and 3 vowels, so its balance is 2. "aeiou" has no consonants and 5 vowels, so its balance is 5.
"rhythm" has 6 consonants (`y` is a consonant) and no vowels, so its balance is 6.
Input: sentence = "b a b"
Output: ["a","b","b"]
Explanation: Every word has balance 1, so all three are sorted alphabetically. The repeated word "b" stays in the result twice.
sentence.length ≤104sentence consists of lowercase English letters and single spacessentence does not start or end with a space