Search
⌘K

Leetcode 2375. Construct Smallest Number From DI String

Given a pattern of 'I' (increasing) and 'D' (decreasing) of length n, produce the lexicographically smallest string of distinct digits 1..9 of length n+1 whose adjacent comparisons match the pattern. Core challenge is to greedily assign the smallest unused digits while handling runs of consecutive 'D's (which force local reversals/stacking) so the overall sequence remains minimal.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Comments

Your account is free and you can post anonymously if you choose.