Big Sorting

Big Sorting

Consider an array of numeric strings where each string is a positive number with anywhere from 1 to 106 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, n, denoting the number of strings in unsorted. Each of the n subsequent lines contains an integer string unsorted[i].

Constraints

  • 1 <= n <= 2 X 105
  • Each string is guaranteed to represent a positive integer without leading zeros.
  • The total number of digits across all strings in unsorted is between 1 and 106 (inclusive).

Output Format

Print each element of the sorted array on a new line.

Sample Input 0

1
2
3
4
5
6
7
6
31415926535897932384626433832795
1
3
10
3
5

Sample Output 0

1
2
3
4
5
6
1
3
3
5
10
31415926535897932384626433832795

Explanation 0

The initial array of strings is unsorted = [31415926535897932384626433832795,1,3,10,3,5].

When we order each string by the real-world integer value it represents, we get:

We then print each value on a new line, from smallest to largest.

Sample Input 1

1
2
3
4
5
6
7
8
9
8
1
2
100
12303479849857341718340192371
3084193741082937
3084193741082938
111
200

Sample Output 1

1
2
3
4
5
6
7
8
1
2
100
111
200
3084193741082937
3084193741082938
12303479849857341718340192371

Solution

1
2
3
4
5
6
7
8
9
10
// Complete the bigSorting function below.
function bigSorting(unsorted) {
return unsorted.sort((a, b) => {
if (a.length == b.length) {
return a > b ? 1 : -1;
}

return a.length - b.length;
});
}
Buy Me A Coffee

Comments

10Days of JS 30Days of Code Algorithm Android Debug Bridge Android Debugging Basic for Web Blog Browsers Chrome으로 Android Debugging 방법 Correctness and the Loop Invariant hackerrank solution in javascript Debug Tools Development Environment in MacOS ES6 Front-End Funny String of Algorithms hackerrank solution in javascript Funny String of Algorithms hackerrank solution in typescript Generator Github Page with Hexo Github Pages HackerRank HackerRank in a String of Algorithms hackerrank solution in javascript HackerRank in a String of Algorithms hackerrank solution in typescript Hexo Hexo Icarus theme Hexo 블로그 만들기 Hexo+Github How Browsers work Insertion Sort - Part 1 hackerrank solution in javascript Insertion Sort - Part 2 hackerrank solution in javascript JS Library JavaScript Level1 Level2 Loops MacOS 개발 환경 설정하기 Mobile web Debugging Node.js Pangrams of Algorithms hackerrank solution in javascript Pangrams of Algorithms hackerrank solution in typescript Problem Solving Programmers Quicksort 1 - Partition hackerrank solution in javascript React RoadMap Running Time of Algorithms hackerrank solution in javascript Safari Debugging Safari Technology Preview Settings Sorting String Strings Strong Password of Algorithms hackerrank solution in javascript TypeScript blog iPhone Safari Debugging 방법 insertion sort 모바일 웹 디버깅 아이폰 사파리를 디버깅하는 방법 안드로이드 디버그 브리지 안드로이드 디버깅하는 방법
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×