Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Remove All Adjacent Duplicates In String (easy)

Problem Statement

Given a string S, remove all adjacent duplicate characters recursively to generate the resultant string.


    • Input: s = "abccba"
    • Output: ""
    • Explanation: First, we remove "cc" to get "abba". Then, we remove "bb" to get "aa". Finally, we remove "aa" to get an empty string.
    • Input: s = "foobar"
    • Output: "fbar"
    • Explanation: We remove "oo" to get "fbar".
    • Input: s = "abcd"
    • Output: "abcd"
    • Explanation: No adjacent duplicates so no changes.


  • 1 <= s




Like the course? Get enrolled and start learning!