AlgoMaster Logo

Numbers At Most N Given Digit Set

digits=[3, 4, 5],n=345
0 / 13
n = 345digits = {3,4,5} · d=33S[0]4S[1]5S[2]ncount L-digit numbers ≤ n, then add every shorter number0dp[0]0dp[1]0dp[2]0basedpbuild numbers digit by digit, keeping them ≤ n
algomaster.io
Step:Count positive integers ≤ 345 whose digits all come from {3, 4, 5} (repeats allowed).