A circular sky-wheel ride has n gondolas mounted at equal spacing around the wheel, numbered 1 through n in order around the circle -- so gondola n is adjacent to gondola 1 as well as to gondola n-1. Each gondola carries a recorded passenger load. To decide where extra structural bracing is needed, the ride operator wants the single largest absolute difference in load between any two gondolas that are adjacent around the circle (including the wraparound pair formed by gondola n and gondola 1).
Line 1: an integer n. Line 2: n space-separated integers, the loads of gondolas 1 through n in order around the wheel.
Print a single integer: the maximum absolute difference between the loads of any two circularly adjacent gondolas.
2 <= n <= 1001 <= load[i] <= 100Example 1
Input
4 1 5 3 6
Expected
5
Explanation
Adjacent pairs going around the wheel: (1,5)->4, (5,3)->2, (3,6)->3, and the wraparound pair (6,1)->5. The largest of these differences is 5.
Example 2
Input
2 10 90
Expected
80
Explanation
With only two gondolas, gondola 1 and gondola 2 are adjacent in both directions around the circle, giving a single distinct pair with difference |10-90| = 80.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →