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
Starting String: Linda's bag of candies spells out "abbaca".
Step 1: Spot the first adjacent duplicate "bb". These candies can't be together. Remove them!
- Result: "aaca"
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".

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?
xxxxxxxxxx
var assert = require('assert');
​
function remove_adjacent_duplicates(s) {
// fill in the solution
return s
}
​
​
try {
assert.equal(remove_adjacent_duplicates('abbaca'), 'ca');
console.log('PASSED: ' + "`remove_adjacent_duplicates('abbaca')` should return `'ca'`");
} catch (err) {
console.log(err);
}
​
try {
assert.equal(remove_adjacent_duplicates('azxxzy'), 'ay');
console.log('PASSED: ' + "`remove_adjacent_duplicates('azxxzy')` should return `'ay'`");
} catch (err) {
console.log(err);
}
​
try {
assert.equal(remove_adjacent_duplicates('aaaa'), '');
console.log('PASSED: ' + "`remove_adjacent_duplicates('aaaa')` should return `''`");
} catch (err) {
console.log(err);
}
​
Here's how we would solve this problem...
How do I use this guide?