Leetcode 1047 — Remove All Adjacent Duplicates In String [Solution]

Nil Madhab
Javarevisited
Published in
3 min readFeb 6, 2021

--

In this series, I am going to solve Leetcode medium problems live with my friends, which you can see on our youtube channel, Today we will do Problem Leetcode: 1047. Remove All Adjacent Duplicates In String.

A little bit about me, I have offers from Uber India and Amazon India in the past, and I am currently working for Booking.com in Amsterdam.

Motivation to learn algorithms

Problem Statement

Given a string S of lowercase letters, a duplicate removal consists of choosing two adjacent and equal letters and removing them.

We repeatedly make duplicate removals on S until we no longer can.

Return the final string after all such duplicate removals have been made. It is guaranteed the answer is unique.

Example 1:

Input: "abbaca"
Output: "ca"
Explanation:
For example, in "abbaca" we could remove "bb" since the letters are adjacent and equal, and this is the only…

--

--

Nil Madhab
Javarevisited

Developer @Booking.com | ex: Samsung, OYO | IIT Kharagpur | Entrepreneur, founder of simplecoding.dev | JOIN Medium, https://nilmadhab.medium.com/membership