Big Sorting — HackerRank — Algorithms — Sorting — 1
Consider an array of numeric strings where each string is a positive number with anywhere from to digits. Sort the array’s elements in non-decreasing, or ascending order of their integer values and print each element of the sorted array on a new line.
Function Description
Complete the bigSorting function in the editor below. It should return the sorted string array.
bigSorting has the following parameter(s):
- unsorted: an unsorted array of integers as strings
Input Format
The first line contains an integer, , denoting the number of strings in .
Each of the subsequent lines contains an integer string .
Constraints
Output Format
Print each element of the sorted array on a new line.
Sample Input 0
6
31415926535897932384626433832795
1
3
10
3
5
Sample Output 0
1
3
3
5
10
31415926535897932384626433832795
Explanation 0
Sample Input 1
8
1
2
100
12303479849857341718340192371
3084193741082937
3084193741082938
111
200
Sample Output 1
1
2
100
111
200
3084193741082937
3084193741082938
12303479849857341718340192371
Solution
Best solution satisfying all time constraints
n = int(input().strip())data = [input().strip() for i in range(n)]# in place sort with two keys, first is the length of the string,
# second is the value itself.# if we do directly with the value x, we do not do so efficiently.data.sort(key = lambda x: (len(x), x))for v in data: print(v)