Largest Number
The Question
Given a list of non negative integers, arrange them such that they form the largest number.
Input: [10,2]
Output: "210"
Input: [3,30,34,5,9]
Output: "9534330"
You can practice it on leetcode before reading the solution
Solution
We need to find the largest number that can be formed by the numbers given to us. The possibilites are N!. Same as sorting so we implement a comparator and sort the array.
Code In Java
Theoretical
Time Complexity: O(Nlog(N))// As it is a sorting process
Space Complexity: O(N)// we have to save all nodes
Leetcode
Memory: 36 MB
Runtime: 4 ms
Evaluation
Time: 94.30%
Space: 87.30%