Skip to content

Practice Increasing Decreasing String

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

Easy#1370
LeetCode Problem

Increasing Decreasing String

Problem Statement

Build a result by repeatedly taking characters from s. On an ascending pass, append the smallest remaining character, then the smallest remaining character strictly greater than the last one appended, continuing until none qualifies. On a descending pass, append the largest remaining character, then the largest remaining character strictly smaller than the last one appended, continuing until none qualifies. Alternate these passes until no characters remain. Remove each selected occurrence from s; identical occurrences are interchangeable. Return the result.

Source: Increasing Decreasing String on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "aaaabbbbcccc"
Output
"abccbaabccba"

# Example 2

Input
s = "rat"
Output
"art"

Constraints

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

Related LeetCode Problems

Practice more problems similar to Increasing Decreasing String.

Review your practice with PhantomCodeAI

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