#3563

Lexicographically Smallest String After Adjacent Removals

grandmaster · 2255 · lc hard +32 · 17.3% accepted · 52 likes · top 1%

Description

Given lowercase string s, repeatedly remove any adjacent pair of alphabetically consecutive characters (either order; alphabet is circular so \'z\' and \'a\' are adjacent).

Return the lexicographically smallest string reachable through any sequence of such operations.

Code

1
2
3