Here is the problem:
You are given an array of digits 0-9 and an integer *n*. The array may contain duplicates of any given digit. Find all the integers which can be formed by contatenating digits from the input array and are less than *n*. Digits from the input array can be repeated in an element in the output.

For example, given as inputs [2, 5, 8] and *n* = 223, then the following should be the output:

[2, 5, 8, 22, 25, 28, 52, 55, 58, 82, 85, 88, 222]

Obviously any integer with fewer digits than *n* would be accepted and any with more denied.
But how to most efficiently find those with the same number of digits?A solution I know of would be to have nested for loops, one for each digit in the input integer, and form every possible combination of digits from the input array and check it against *n*. This seems clunky though and I'm wondering if there's a better way.