hardDynamic ProgrammingString 0 views

Lexicographically Smallest 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 can perform the following operation any number of times (including zero):

Return the lexicographically smallest string that can be obtained after performing the operations optimally.

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

Lexicographically Smallest String After Adjacent Removals diagram

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.

Hints

Companies

No companies reported yet.

Discussion

Sign in to join the discussion.

Loading discussion...

Test results

No test cases yet.