← Questions

Smallest number from an increase and decrease pattern

0
AirbnbCodingLast asked Feb 2026

Given a pattern of I (increase) and D (decrease) characters of length n, build the smallest number of n + 1 distinct digits from 1 to 9 whose consecutive digits follow the pattern. Push digits onto a stack and pop them all whenever you see an I or reach the end.

Write and test your solution herePython in your browser, the question's tests level by level, saved for you.Sign in to start coding