#C10001. Remove Adjacent Duplicates
Remove Adjacent Duplicates
Remove Adjacent Duplicates
Given a string s consisting of lowercase alphabets, remove all adjacent duplicate characters repeatedly until no more removals can be performed.
This process is defined as follows: if two consecutive characters s[i] and s[i+1] are the same, they are both removed. Formally, while there exists an index \(i\) such that \(s[i] = s[i+1]\), remove both characters from the string. The operation is applied repeatedly until the string cannot be reduced further.
For example:
- If the input is
abbaca
, the output isca
. - If the input is
azxxzy
, the output isay
.
inputFormat
A single line containing the string s composed of lowercase alphabets.
outputFormat
A single line containing the resultant string after all adjacent duplicates have been removed.## sample
abbaca
ca