Skip to content

Practice Apply Operations to Make String Empty

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

Medium#3039
LeetCode Problem

Apply Operations to Make String Empty

Problem Statement

Starting with s, perform rounds until it is empty. In one round, remove the first occurrence of every lowercase letter from a through z that is present, keeping the relative order of all remaining characters. Return the string immediately before the final round. For instance, aabcbbca becomes abbca, then ba, then empty, so the returned string is ba.

Source: Apply Operations to Make String Empty on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "aabcbbca"
Output
"ba"

# Example 2

Input
s = "abcd"
Output
"abcd"

Constraints

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

Related LeetCode Problems

Practice more problems similar to Apply Operations to Make String Empty.

Review your practice with PhantomCodeAI

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