DEV Community

ZeeshanAli-0704
ZeeshanAli-0704

Posted on

Super Reduced String

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


Enter fullscreen mode Exit fullscreen mode

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay