HackerRank Challenge Solution: The Love Letter Mystery
I solved a coding challenge in HackerRank today. The challenge is called The Love Letter Mystery. Check out my solution below.
I think my solution is not elegant π I could improve it.
The solution idea:
- inputs is an array of String.
- each element is just a String type object. A String type object is a collection of Character type.
- Convert a String to an array of Int type. e.g. [βaβ, βbβ, βcβ] -> [97, 98, 99]
- Also create the reversed version. [βcβ, βbβ, βaβ] -> [99, 98, 97]
- Compare each element. the first element of the normal version should be compared with the first element of the reversed version.
- If the reversed versionβs element is greater than the normal, get the difference of the value. The value is how many times to decrement the reversed version to match with the normal.
- Sum up the difference values.