You are given a string s. Your task is to remove all consecutive duplicate characters. If the same characters appear next to each other, keep only one occurrence. Return the final string after removing duplicates.
Input: s = "aabbccdaa"
Output: "abcda"
Explanation: Consecutive duplicate characters are removed.

Input: s = "aaaa"
Output: "a"
Explanation: All duplicates are consecutive, so only one character remains.

Input: s = "abca"
Output: "abca"
Explanation: No consecutive duplicates are present, so the string remains unchanged.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
aaabbcdd
abcd
mississippi
misisipi