1 through size can be written as a string in many orders, size! of them in total. Sort all those strings in increasing order, the way words are sorted in a dictionary.
Return the string that sits at position rank in that list (counting from one).
There is no need to list every ordering: try to build the answer digit by digit.size=3, rank=4 → '231'
The orderings of 1, 2, 3 in increasing order are 123, 132, 213, 231, 312, 321. The fourth one is "231".
size=4, rank=14 → '3142'
The first 6 orderings start with 1 and the next 6 with 2, so the 14th starts with 3 and is the second in its group: "3142".
size=1, rank=1 → '1'
size=3, rank=4
'231'
Run checks the first 3 tests in your browser. Submit checks all 59 tests on the server, hidden ones included.