Mark As Completed Discussion

Good morning! Here's our prompt for today.

The Concept: Removing Adjacent Duplicates

Imagine you're attending a magical carnival where you can pull adjacent duplicate letters from a string like pulling rabbits out of a hat. Exciting, right? Your goal is to get a clean string with no adjacent duplicates. In this lesson, we'll explore this problem with Linda's candy adventure.

The Problem

Linda loves candies and messages, so she wants to write a message on her cake with candies. However, she can't have adjacent duplicate candies; they need to be unique. Can you help her?

Objective: Help Linda by removing all adjacent duplicate letters until you get a string with no adjacent duplicates.

Visual Walkthrough: Unpacking the Bag of Candies

  1. Starting String: Linda's bag of candies spells out "abbaca".

  2. Step 1: Spot the first adjacent duplicate "bb". These candies can't be together. Remove them!

    • Result: "aaca"
  3. Step 2: Next, we have another adjacent duplicate "aa". Let's remove those as well.

    • Result: "ca"

And voila! We're left with a string that doesn't have any adjacent duplicates, and it spells out "ca".

Question

Constraints: The Boundaries of Our Magical Carnival

  • The length of the string s will be between 1 and (10^5).
  • The string s will only consist of lowercase English letters.

Try to solve this here or in Interactive Mode.

How do I practice this challenge?

JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

Here's how we would solve this problem...

How do I use this guide?