Find the missing letter

jenny
Membre
Inscrit depuis le: 2025-08-24 15:11:06
2024-06-03 17:20:00

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'
(Use the English alphabet with 26 letters!)

Image preview

blessedtechie
Admin
Inscrit depuis le:
2024-06-03 18:28:32

Image preview
Instead of calculating the difference between the first and last characters, we iterate through the array to check each pair of consecutive characters. For each character, we check if the ASCII value of the next character is one more than the current character. If it isn't, we find the missing character by adding one to the ASCII value of the current character. Once the missing character is identified, we return it immediately.

This approach ensures that we correctly identify the missing letter regardless of its position in the array.

jenny
Membre
Inscrit depuis le: 2025-08-24 15:11:06
2024-07-02 22:17:32

@blessedtechie I love your approach to solving this problem. It will be good for others to write these in their own favourage programming languages though.

jenny
Membre
Inscrit depuis le: 2025-08-24 15:11:06
2024-07-25 10:37:44
[[9,31],[29]]
Facebook X (Twitter) Instagram LinkedIn Telegram WhatsApp