Skip to content

Practice Construct Smallest Number From DI String

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

Medium#2375
LeetCode Problem

Construct Smallest Number From DI String

Problem Statement

Return the lexicographically smallest digit string of length pattern.length + 1 using digits 1 through 9 without repetition. For every i, pattern[i] = I requires num[i] < num[i + 1], and D requires num[i] > num[i + 1].

Source: Construct Smallest Number From DI String on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
pattern = "IIIDIDDD"
Output
"123549876"

# Example 2

Input
pattern = "DDD"
Output
"4321"

Constraints

1 <= pattern.length <= 8
pattern consists of only the letters 'I' and 'D'.

Related LeetCode Problems

Practice more problems similar to Construct Smallest Number From DI String.

Review your practice with PhantomCodeAI

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