Frog Jump 2
There are N stones, numbered 1, 2, ..., N. The height of the i-th stone is given by an array h where h[i] represents the height of stone i.
A frog is initially on Stone 1 and wants to reach Stone N. If the frog is on Stone i, it can jump either to Stone i+1 or Stone i+2.
The cost of jumping from Stone i to Stone j is the absolute difference in their heights: |h[i] - h[j]|. Find the minimum possible maximum jump cost incurred before the frog reaches Stone N.
Example 1:
Input: N = 4 , h = [10, 30, 40, 20]
Output: 20
Explanation: Possible paths:
Path 1: 0 → 1 → 3 Costs: 20, 10 → max = 20 Path 2: 0 → 2 → 3 Costs: 30, 20 → max = 30
Answer = 20
Example 2:
Input: N = 2 , h = [10, 10]
Output: 0
Explanation: For Path: 1 -> 2. Cost: |10 - 10| = 0.
Now Your Turn!
Pick the correct output for the given inputInput: N = 6 , h = [30, 10, 60, 10, 60, 50]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 2 <= N <= 105
- 1 <= h[i] <= 109