The question reads :
You are given an array of numbers (not digits, but numbers: e.g. 9, 23, 184, 102, etc.) - you need to construct the largest number from it. For example: you get 21, 2, 10 - the largest number is 22110. (Emphasis mine)
In a comment it was stated :
The task basically was to decompose the numbers into digits and then rearrange those digits to form the largest possible value that could be represented by these digits
Those two statements are very different and I'd tend to believe you either misunderstood the interview question or you didn't explain it properly. The example you gave, 22110 isn't constructed by the numbersdigits [2,2,1,1,0]
, but by the digitsnumbers [2,21,10]
. This fits much more with how you worded your question.
With your code, getting an input of [20,210,32]
would yield the result 3222100
, but the actual answer should be 3221020
because of [32,210,20]
.
At least, this is all assuming that the requirements that you put in your questions are specifically the one you received in the interview, meaning you misunderstood the question.