All practice tasks

Coding (Algo)

Cancel Adjacent Actions

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 from solve.

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

What this task practices

Cancel Adjacent Actions is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as easy difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.