Skip to content

Practice Lexicographically Smallest String After Adjacent Removals

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#3563
LeetCode Problem

Lexicographically Smallest String After Adjacent Removals

Problem Statement

Given lowercase s, you may repeatedly remove any adjacent pair whose letters are consecutive in the circular alphabet, in either order; a and z are consecutive. Close the gap after each removal. Return the lexicographically smallest string obtainable, including the option to perform no removals.

Source: Lexicographically Smallest String After Adjacent Removals on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "abc"
Output
"a"

# Example 2

Input
s = "bcda"
Output
""

# Example 3

Input
s = "zdce"
Output
"zdce"

Constraints

1 <= s.length <= 250
s consists only of lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Lexicographically Smallest String After Adjacent Removals.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.