Remove All Adjacent Duplicates In String

Easy

Description

Given a string s, repeatedly remove adjacent duplicate letters. Continue removing duplicates until no adjacent pair of equal characters remains.

Examples

Input:s = "abbaca"
Output:"ca"
Explanation:

Remove bb, then aa.

Input:s = "abccba"
Output:""
Explanation:

Remove cc to get "abba", then remove bb to get "aa", finally remove aa to get empty string.

Input:s = "aabbccdd"
Output:""
Explanation:

Remove aa to get "bbccdd", then remove bb to get "ccdd", then remove cc to get "dd", finally remove dd to get empty string.

Constraints

  • 1 ≤ s.length ≤ 10⁵

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!