2-Way Partition solved by 1097

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

Topics: Sorting

Problem

A partition procedure is an essential part of the Quick Sort algorithm, the subject of one of the following problems. Its main goal is to put the first element of a given array to its proper place in a sorted array. It can be implemented in linear time, by a single scan of a given array. Moreover, it is not hard to come up with an in-place algorithm.

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

Return: A permuted array B[1..n] such that it is a permutation of A and there is an index 1qn such that B[i]A[1] for all 1iq1, B[q]=A[1], and B[i]>A[1] for all q+1in.

Sample Dataset

9
7 2 5 6 1 3 9 4 8

Sample Output

5 6 3 4 1 2 7 9 8

Please login to solve this problem.

Welcome to Rosalind!

Rosalind is a platform for learning bioinformatics through problem solving.
Please login with Google/Twitter/Facebook or register a new account.