Back to problems

Bounded Number Construction from Allowed Digits

Algorithm · ByteDance · Hard

Largest Smaller Integer Medium · Greedy, Backtracking, Math · Company Tags · Hints: Build greedily from left to right; when a prefix matches the bound, try the largest eligible digit less than the current digit of N, then fill the rest with the maximum allowed digit. If that fails, backtrack. You are given a string N representing a positive integer (without leading zeros) and a set of distinct decimal digits A (each between 0 and 9). Construct the greatest possible integer…

Checking your access…