Skip to content

Find the Missing Letter

Write a method that takes an array of consecutive (increasing) letters as input and that returns the missing letter in the array.

You will always get an valid array. And it will be always exactly one letter be missing. The length of the array will always be at least 2.

The array will always contain letters in only one case.

Example

['a','b','c','d','f'] -> 'e'
['O','Q','R','S'] -> 'P'

Solution

py
def find_the_missing_letter(chars):
    for i in range(len(chars)):
        if ord(chars[i]) + 1 != ord(chars[i + 1]):
            return chr(ord(chars[i]) + 1)
    return None


print(find_the_missing_letter(['a', 'b', 'c', 'd', 'f']))

my thoughts are neither my employer's nor my wife's