Stack · Easy
A gesture log contains reversible toggles: two adjacent equal actions cancel. Cancellations can expose another cancellable pair.
Return the fully reduced action string.
Input
Call
- Implement
solve(input)and return its result. Do not print fromsolve.
Input object
{ actions:string }
Input rules
- Lowercase ASCII characters identify toggle kinds.
What each field means
actions— lowercase action characters in execution order.
Output
Return value and rules
- Repeatedly remove adjacent equal pairs until no pair remains.
- A removal may create another removable pair; continue until fully reduced.
- Return the remaining string, or
""if everything cancels.
Constraints
- 0 <= actions.length <= 100000
Examples
Example 1
{
"actions": "abbaca"
}Returns
"ca"Example 2
{
"actions": ""
}Returns
""Required complexity
O(n) time and O(n) space