Source Code:
073_NumberOf1.c
Test Cases:
• Functional Test Cases (Input 5, 10, 55, 99, ...)
• Boundary Test Cases (Input 0, and 1)
• Performance Test Cases (Input some large numbers, such as 10000, 21235)
Concatenate an Array to Get a Minimum Number
?Question 74 Big numbers can be formed if numbers in an array are concatenated together. How do you
print the minimum concatenated number of a given array?
For example, if the input array is {3, 32, 321}, there are six concatenated numbers and the minimum one is
321323.
An intuitive solution for this problem is to get all permutations of the given array at first and then
concatenate each permutation together. The minimum concatenated number is selected after all
concatenated permutations are compared. We have discussed permutation in the section Permutations
and Combinations.
As we know, there are $n!$ permutations for an array with $n$ element, so this intuitive solution costs
O($n!$) time. Let's explore more efficient solutions.