Processing math: 100%

3-Way Partition solved by 892

Feb. 21, 2014, 4:25 p.m. by Rosalind Team

Topics: Sorting

Problem

This problem is very similar to “2-Way Partition”, but now the goal is to partition an input array more carefully.

Given: A positive integer n105 and an array A[1..n] of integers from 105 to 105.

Return: An array B[1..n] such that it is a permutation of A and there are indices 1qrn such that B[i]<A[1] for all 1iq1, B[i]=A[1] for all qir, and B[i]>A[1] for all r+1in.

Sample Dataset

9
4 5 6 4 1 2 5 7 4

Sample Output

2 1 4 4 4 5 7 6 5

Please login to solve this problem.