Given a lowercase string that has alphabetic characters only and no spaces, implement a function that will return the highest value of consonant substrings. Consonants are any letters of the alphabet except "aeiou".
We shall assign the following values: a = 1, b = 2, c = 3, .... z = 26.
For example, for the word "zodiacs", let's cross out the vowels. We get: "z, d, cs". The values are z = 26, d = 4 and cs = 3 + 19 = 22. The highest is 26.
solve("zodiacs") = 26
For the word "strength", solve("strength") = 57
-- The consonant substrings are: "str" and "ngth" with values "str" = 19 + 20 + 18 = 57 and "ngth" = 14 + 7 + 20 + 8 = 49. The highest is 57.
Tests
solve("chruschtschov") => 80
solve("khrushchev")
solve("strength")
solve("catchphrase")
solve("twelfthstreet")
solve("mischtschenkoana")
Good luck!
This challenge comes from KenKamau on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (13)
Scala
I've always appreciated Scala solutions for their mixed-notation to function-call chaining, it's truly bizarre. 😲
Here is a Python one-liner
Javascript solution
Nice! Here's my implementation:
Very nice, I wasn't aware of the
c.charCodeAt(0) - 96
rule, didn't work with chars very much in all these years to be honest.It only works with lowercase a to z, because UTF-16 represents them as contiguous code points, starting at 97.
Elixir
Go, single-pass
Java Streams
C++ solution using simple for-loop
Rust:
C