Minimize the Longest Jump on a Round Trip through Ordered Stones

Quick Overview

Minimize the longest jump in a frog’s round trip through ordered stones, reaching the last stone and returning without reusing intermediate landings.

Minimize the Longest Jump on a Round Trip through Ordered Stones

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem The frog starts at stones[0]=0, must reach the last stone, then return to the first. It may jump to each stone at most once; the initial placement is not a landing jump, so the required return to the first stone is allowed. Each jump costs the absolute difference in positions. Return the smallest possible maximum jump over the round trip. ```cpp class Solution { public: int maxJump(vector<int>& stones); }; ``` ### Examples **Example 1:** ```text Input: stones = [0,1,4,6] Output: 5 Explanation: Route 0->4->6->1->0 has jumps4,2,5,1 and visits each interior stone once. ``` **Example 2:** ```text Input: stones = [0,8] Output: 8 Explanation: Both the outward and return jumps span 8. ``` ### Constraints - `2 <= stones.length <= 100000`. - `0 <= stones[i] <= 10^9`, with stones[0]=0. - Positions are strictly increasing. ### Clarifying Questions - Is the return to the first stone required? Yes. The initial placement is not a landing, so returning there is permitted. - Must all other stones be used? No. - Can an intermediate stone be landed on twice? No. - Is cost the sum of jump lengths? No; it is the longest jump in the round trip. ```hint Check the boundary Check the complete outward-and-return journey, rather than just one direction. ```

Overview: Minimize the longest jump in a frog’s round trip through ordered stones, reaching the last stone and returning without reusing intermediate landings.

Google logo
Google
Source window: 0–6 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

The frog starts at stones[0]=0, must reach the last stone, then return to the first. It may jump to each stone at most once; the initial placement is not a landing jump, so the required return to the first stone is allowed. Each jump costs the absolute difference in positions. Return the smallest possible maximum jump over the round trip.

class Solution {
public:
    int maxJump(vector<int>& stones);
};

Examples

Example 1:

Input: stones = [0,1,4,6]
Output: 5
Explanation: Route 0->4->6->1->0 has jumps4,2,5,1 and visits each interior stone once.

Example 2:

Input: stones = [0,8]
Output: 8
Explanation: Both the outward and return jumps span 8.

Constraints

  • 2 <= stones.length <= 100000 .
  • 0 <= stones[i] <= 10^9 , with stones[0]=0.
  • Positions are strictly increasing.

Clarifying Questions Guidance

  • Is the return to the first stone required? Yes. The initial placement is not a landing, so returning there is permitted.
  • Must all other stones be used? No.
  • Can an intermediate stone be landed on twice? No.
  • Is cost the sum of jump lengths? No; it is the longest jump in the round trip.