Just try working with sub-string & index
function superReducedString(s) {
let left = 0;
let right = 1;
let subStr = s;
while (right <= subStr.length)
if (subStr[left] === subStr[right]) {
subStr = subStr.substring(0, left) + subStr.substring(right + 1);
left = 0;
right = 1;
i = 0;
} else {
left++;
right++;
}
return subStr;
}
console.log(
"Answere here ====>",
superReducedString(
"kagoyzkgfjnyvjewazalxngpdcfahneqoqgiyjgpzobhaghmgzmnwcmeykqzgajlmuerhhsanpdtmrzibswswzjjbjqytgfewiuu"
)
);
// kagoyzkgfjnyvjewazalxngpdcfahneqoqgiyjgpzobhaghmgzmnwcmeykqzgajlmuersanpdtmrzibswswzbjqytgfewi-> output