Tap here to switch tabs
Problem
Submissions

Problem: Construct Smallest Number From DI String

med
30 min
Try to solve the Construct Smallest Number From DI String problem.

Statement

You are given a 00 indexed string pattern of length nn consisting of the characters 'I' meaning increasing and 'D' meaning decreasing.

Create a string num of length n+1n + 1 that satisfies the following conditions:

  • num consists of the digits ′1′'1' through ′9′'9', where each digit is used at most once.

  • If pattern[i] is equal to 'I', then num[i] < num[i + 1].

  • If pattern[i] is equal to 'D', then num[i] > num[i + 1].

Return the lexicographically smallest possible string num that meets these conditions.

Constraints:

  • 1≤1 \leq pattern.length ≤8\leq 8

  • pattern consists of only the letters 'I' and 'D'.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Construct Smallest Number From DI String

med
30 min
Try to solve the Construct Smallest Number From DI String problem.

Statement

You are given a 00 indexed string pattern of length nn consisting of the characters 'I' meaning increasing and 'D' meaning decreasing.

Create a string num of length n+1n + 1 that satisfies the following conditions:

  • num consists of the digits ′1′'1' through ′9′'9', where each digit is used at most once.

  • If pattern[i] is equal to 'I', then num[i] < num[i + 1].

  • If pattern[i] is equal to 'D', then num[i] > num[i + 1].

Return the lexicographically smallest possible string num that meets these conditions.

Constraints:

  • 1≤1 \leq pattern.length ≤8\leq 8

  • pattern consists of only the letters 'I' and 'D'.