SDE Path

Quick Sort Implementation

Medium

Quick Sort Implementation

Implement quicksort using the Lomuto partition scheme and analyze worst-case input.

Input format

The first line contains N. The second line contains N space-separated integers.

Output format

Print the array sorted in non-decreasing order, space-separated on one line.

Constraints

  • Values fit in a 64-bit signed integer
  • Trailing whitespace and a trailing newline are ignored by the judge

Read from stdin, write to stdout. Sample cases below show the exact format.

Sample cases

Example 1
Input
5
5 2 8 1 9
Expected output
1 2 5 8 9
Example 2
Input
4
3 1 2 1
Expected output
1 1 2 3