FastPrepFrog Jump: Minimum Energy
Problems/Frog Jump: Minimum Energy

Frog Jump: Minimum Energy

Mygate logoMygate● MediumFULLTIMEPHONE SCREEN

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names Frog Jump with recursion, dynamic programming, and space optimization but omits its rules. This exercise chooses one- or two-step jumps with height-difference energy, rather than a counting or reachability variant; it matches the named task at about 70%.

A frog starts on the first stone of a nonempty array heights. From stone i, it may jump forward to i + 1 or i + 2, provided that stone exists.

A jump from stone i to stone j costs abs(heights[i] - heights[j]) units of energy. Return the minimum total energy needed to reach the last stone.

The frog pays no energy before its first jump. For a single stone, return 0.

Function

frogJump(heights: int[]) → long

Examples

Example 1

heights = [10,20,30,10]return = 20

Jump through stones 0, 1, 3: costs 10 + 10 = 20.

Example 2

heights = [10,30,40,20]return = 30

Jump through stones 0, 1, 3: costs 20 + 10 = 30.

Example 3

heights = [7]return = 0

The frog already occupies the last stone.

Constraints

  • 1 <= heights.length <= 10^5
  • -10^9 <= heights[i] <= 10^9
  • Use signed 64-bit arithmetic for total energy and height differences.

More Mygate Phone Screen questions

  • Employees Earning More Than Their ManagerPHONE SCREEN · Seen Sep 2026
  • Maximum Subarray SumPHONE SCREEN · Seen Sep 2026
  • Reverse a Linked ListPHONE SCREEN · Seen Sep 2026
  • Users Active in Both January and FebruaryPHONE SCREEN · Seen Sep 2026
  • Elements Occurring More Than n/3 TimesPHONE SCREEN · Seen Jan 2025
  • Left View of a Binary TreePHONE SCREEN · Seen Jan 2025
  • Two SumPHONE SCREEN · Seen Aug 2024
  • Minimum in a Rotated Sorted ArrayPHONE SCREEN · Seen Jul 2024
  • Minimum Subarray SumPHONE SCREEN · Seen Sep 2023
  • Remove the Nth Node from the EndPHONE SCREEN · Seen Sep 2023

Similar questions at other companies

  • Maximum Subarray Sum with One DeletionServiceNow · PHONE SCREENServiceNow interview questions
  • Maximum Product of a Contiguous SubarrayLinkedIn · PHONE SCREENLinkedIn interview questions
  • Fewest Coins CombinationBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Longest Increasing SubsequenceByteDance · PHONE SCREENByteDance interview questions
  • Jump GamePaytm · PHONE SCREENPaytm interview questions
  • Query Words Within K PositionsPalantir · PHONE SCREENPalantir interview questions
  • House RobberVisa · PHONE SCREENVisa interview questions
  • Best Improvement Period of at Least K IntervalsAmazon · PHONE SCREEN
  • Longest Increasing SubsequenceAngel One · PHONE SCREEN
  • Match Shops and BuyersGoogle · PHONE SCREENGoogle interview questions
All Mygate interview questionsSee Mygate hiring insights
Saved
class Solution {
    public long frogJump(int[] heights) {
        // write your code here
    }
}
Checking account…