6 kyu

Vowel-consonant lexicon

303 of 608KenKamau

Description:

If we alternate the vowels and consonants in the string "have", we get the following list, arranged alphabetically: ['ahev', 'aveh', 'ehav', 'evah', 'have', 'heva', 'vahe', 'veha']. These are the only possibilities in which vowels and consonants are alternated. The first element, ahev, is alphabetically lowest.

Given a string:

  • alternate the vowels and consonants and return the lexicographically lowest element in the list
  • If any two or more vowels or consonants must follow each other, return "failed"
  • if the number of vowels and consonants are equal, the first letter of the result must be a vowel.

Examples:

solve("codewars") = "failed". However you alternate vowels and consonants, two consonants must follow each other
solve("oruder") = "edorur"
solve("orudere") = "ederoru". This is the only option that allows you to alternate vowels & consonants.
In C, return an allocated string even if the response is "failed".

Vowels will be any of "aeiou". Input will be a lowercase string, no spaces. See test cases for more examples.

Good luck!

If you like this Kata, please try:

Consonant value

Alternate capitalization

Strings
Arrays
Algorithms

Stats:

CreatedSep 30, 2017
PublishedOct 1, 2017
Warriors Trained1386
Total Skips27
Total Code Submissions2279
Total Times Completed608
Python Completions303
JavaScript Completions231
Haskell Completions34
Ruby Completions41
C Completions32
Total Stars66
% of votes with a positive feedback rating92% of 194
Total "Very Satisfied" Votes166
Total "Somewhat Satisfied" Votes24
Total "Not Satisfied" Votes4
Total Rank Assessments10
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • KenKamau Avatar
  • Voile Avatar
  • rowcased Avatar
  • hobovsky Avatar
Ad