We will discuss the solution to Jump on Platforms from AIO 2026.
There are only two platforms, so we only make one jump: from platform 1 to platform 2. This jump has length P2 - P1, which is our answer. For example, in sample input 1 the platforms are at positions 3 and 5, so the answer is 5-3 = 2.
There are now two jumps: from platform 1 to platform 2, and from platform 2 to platform 3. These jumps have lengths P2 - P1 and P3 - P2, and the answer is the larger of the two. For example, in sample input 2 the jumps have lengths 2-1 = 1 and 5-2 = 3, so the answer is 3.
We can extend the same idea to any number of platforms. We consider the jumps one at a time while storing the longest jump we have seen so far. For each platform i from 2 to N, the jump onto platform i has length Pi - Pi-1. If this is longer than the longest jump so far, we update our answer.
Let's try this on sample input 3, where the platforms are at positions 5, 6, 7, 11, and 14:
This solution has a time complexity of O(N) which is fast enough to score 100 in this problem.
We can code this solution using a for loop and max.
Below you can see this solution written in Python and C++.
I suggest trying to code the solution yourself and only look at our code after you finish or if you get stuck.
# N is the number of platforms.
N = 0
# P contains the positions of the platforms. Note that the list starts from 0,
# and so the values are P[0] to P[N-1].
P = []
# Read the value of N and the positions of the platforms.
N = int(input().strip())
P = list(map(int, input().strip().split()))
# Compute the answer
answer = 0
for i in range(1, N):
# The jump from platform i-1 to platform i
jump = P[i] - P[i-1]
answer = max(answer, jump)
print(answer)
#include <cstdio>
#include <algorithm> // for std::max
/* N is the number of platforms. */
int N;
/*
* P contains the positions of the platforms. Note that the array starts from
* 0, and so the values are P[0] to P[N-1].
*/
int P[200005];
int main(void) {
/* Read the value of N and the positions of the platforms. */
scanf("%d", &N);
for (int i = 0; i < N; i++) {
scanf("%d", &P[i]);
}
/* Compute the answer */
int answer = 0;
for (int i = 1; i < N; i++) {
// The jump from platform i-1 to platform i
int jump = P[i] - P[i-1];
answer = std::max(answer, jump);
}
printf("%d\n", answer);
}