function modifyString(s: string): string {
const strs: string[] = [...s];
strs.forEach((value: string, index: number, array: string[]) => {
if (value !== '?') {
return s;
}
const last = array[index - 1],
next = array[index + 1];
if (!last && (!next || next === '?')) {
array[index] = 'a';
} else if (!last) {
array[index] = getNextChar(next);
} else if (!next) {
array[index] = getNextChar(last);
} else {
array[index] = getNextChar(last) !== next ? getNextChar(last) : getNextChar(next);
}
});
return strs.join('');
};
function getNextChar(char: string): string {
return String.fromCharCode(
(char.charCodeAt(0) - 96) % 26 + 97
);
}