You are given a sorted list of characters representing digits. You can form numbers by using these digits freely, and each digit may be used multiple times.
Your task is to determine how many positive integers can be created using only these digits such that the resulting number is less than or equal to a given integer n.
You may generate numbers of any length (1 digit, 2 digits, 3 digits, etc.), as long as the number does not exceed n.
Input: digits = ["1","5"], n = 60
Output: 6
Explanation:
Valid numbers: 1,5,11,15,51,55.
Input: digits = ["2","4","8"], n = 500
Output: 15
Explanation:
All valid numbers include: 2,4,8,22,24,28,42,44,48,82,84,88,222,224,228 → total 15.
Input: digits = ["3","9"], n = 3
Output: 1
Explanation:
Only "3" ≤ 3.
Accepted:
Submission: