Lexicographically Maximal Resulting Array
MediumAsked in:Amazon•Stage:Online Assessment
arraygreedy
Problem Statement
Given an array of integers, you may repeatedly move the first element to the end (i.e., rotate the array). Determine the rotation that yields the lexicographically maximal resulting array and output that array.
Input Format
The first line contains an integer n, the size of the array. The second line contains n space-separated integers a1,…,an.
Output Format
Print the lexicographically maximal array after any number of rotations as n space-separated integers.
Constraints
- 1 <= n <= 10^5
- -10^9 <= ai <= 10^9