/**
* Question:
* Write a method that takes an array of consecutive (increasing) letters as
* input and that returns the missing letter in the array.
*
* Input Constrains:
* You will always get a 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.
*/
function findMissingLetter(arr) {
// Base condition
// When array length is less than 2 then the second letter is missing.
if (arr.length <= 2) {
return String.fromCharCode(arr[0].charCodeAt(0) + 1);
}
const midPos1 = Math.floor((arr.length-1)/2);
const midPos2 = Math.floor(arr.length/2);
const start = arr[0].charCodeAt(0);
const mid1 = arr[midPos1].charCodeAt(0);
const mid2 = arr[midPos2].charCodeAt(0);
const end = arr[arr.length - 1].charCodeAt(0);
if (mid1 - start > end - mid2) {
return findMissingLetter(arr.slice(0, midPos1));
} else if (mid1 - start < end - mid2) {
return findMissingLetter(arr.slice(midPos2));
} else {
// If both split are equal then the letter missing is at the center.
return String.fromCharCode(mid1 + 1);
}
}
while ((str = readline())) {
console.log(findMissingLetter(str.split('')));
}