mediumSimulationStackString 0 views

Resulting String After Adjacent Removals

You are given a string s consisting of lowercase English letters.

You are given a string s consisting of lowercase English letters.

You must repeatedly perform the following operation while the string s has at least two consecutive characters:

Return the resulting string after no more operations can be performed.

Note: Consider the alphabet as circular, thus 'a' and 'z' are consecutive.

Resulting String After Adjacent Removals diagram

Example 1

Input: s = "abc"

Output: "c"

Example 2

Input: s = "adcb"

Output: ""

Example 3

Input: s = "zadb"

Output: "db"

Constraints

  • 1 <= s.length <= 10^5
  • s consists only of lowercase English letters.

Hints

Companies

No companies reported yet.

Discussion

Sign in to join the discussion.

Loading discussion...

Test results

No test cases yet.