Stalin Sort

View as PDF

Submit solution

Points: 3
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

A specific sorting algorithm is as follows:

You iterate down the list of elements checking if they're in increasing order. Any element which is out of order is eliminated. At the end you have a sorted list.

Can you implement it?

Input Specifications

The first line will contain an integer N (1 \le N \le 10^5).

The next N lines will contain an integer i (1 \le i \le 10^9), integers of a list that you are to operate Stalin Sort on.

Sample Input 1

7
1
4
3
2
5
5
2

Sample Output 1

1
4
5
5

Sample Explanation

The output is 1 4 5 5 because Stalin will walk from 1 to 4, 4 to 3, kicking 3 out, and so on.


Comments

There are no comments at the moment.