FastPrepAt Most K Jumps with Quadratic Transition Cost
Problems/At Most K Jumps with Quadratic Transition Cost

At Most K Jumps with Quadratic Transition Cost

Infosys logoInfosys● HardFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This is an Infosys assessment question that has been reported twice. You move from the first index to the last one with forward jumps only, with a limit of K jumps. Each jump costs the square of the gap between the two sorted positions plus a fee for the index you land on, and you want the smallest total.

Both reports give K up to 100, and the newer one also gives the array length, up to 100,000. Neither says whether the starting index is charged, how large the positions and fees can be, whether a fee can be negative, or what the function looks like. We do not charge the start, chose positions from 0 to 100,000 and landing costs from 0 to 1,000,000, number the indices from 0, and wrote the three examples ourselves.

Our version is about 93% the same as the reported question.

You are given two integer arrays positions and landingCosts of the same length n, and an integer maxJumps. The indices are 0 to n - 1, and positions is sorted in nondecreasing order.

You start at index 0 and want to reach index n - 1. Every jump goes forward, from an index i to any index j with i < j. A jump from i to j costs (positions[i] - positions[j]) * (positions[i] - positions[j]) + landingCosts[j]: the square of the gap between the two positions, plus the landing cost of the index you land on.

You may use at most maxJumps jumps. Return the minimum total cost to reach index n - 1.

The starting index is free: landingCosts[0] is never paid. If n == 1, you are already at the last index, so the answer is 0.

Function

minimumQuadraticJumpCost(positions: int[], landingCosts: int[], maxJumps: int) → long

Examples

Example 1

positions = [0,2,5]landingCosts = [0,3,1]maxJumps = 2return = 17

With maxJumps = 2 there are two routes to index 2. The direct jump 0 -> 2 costs (0 - 5) * (0 - 5) + 1 = 26. The route 0 -> 1 -> 2 costs (0 - 2) * (0 - 2) + 3 = 7 for the first jump and (2 - 5) * (2 - 5) + 1 = 10 for the second, 17 in total. So the answer is 17.

Example 2

positions = [0,1,4,10]landingCosts = [0,5,2,3]maxJumps = 2return = 57

There are three routes to index 3 with at most 2 jumps. 0 -> 3 costs 100 + 3 = 103, 0 -> 1 -> 3 costs (1 + 5) + (81 + 3) = 90, and 0 -> 2 -> 3 costs (16 + 2) + (36 + 3) = 57. The route 0 -> 1 -> 2 -> 3 would cost only (1 + 5) + (9 + 2) + (36 + 3) = 56, but it uses 3 jumps, more than maxJumps = 2. So the answer is 57.

Example 3

positions = [1,1,2]landingCosts = [0,4,1]maxJumps = 2return = 2

The direct jump 0 -> 2 costs (1 - 2) * (1 - 2) + 1 = 2. The route 0 -> 1 -> 2 has a gap of 0 on its first jump but still pays landingCosts[1] = 4, then (1 - 2) * (1 - 2) + 1 = 2, so it costs 6. So the answer is 2.

Constraints

  • 1 <= n <= 100000, where n = positions.length
  • landingCosts.length == n
  • 0 <= positions[i] <= 100000
  • positions[i] <= positions[i + 1] for every 0 <= i < n - 1
  • 0 <= landingCosts[i] <= 1000000
  • 1 <= maxJumps <= 100

More Infosys Online Assessment questions

  • Hiking Club Fastest PaceOA · Seen Nov 2026
  • Lowest Common Ancestor with a Changing RootOA · Seen Nov 2026
  • Minimum Leaf Path Sum over All RootsOA · Seen Nov 2026
  • Split Array to Minimize the Largest SumOA · Seen Nov 2026
  • Cherry PickupOA · Seen Nov 2026
  • Lexicographically Smallest Grid Path with One Letter ChangeOA · Seen Nov 2026
  • Minimum Cost to Supply Water with Wells and PipesOA · Seen Nov 2026
  • Minimum Cost to Tile a Strip with Widths 1, 2, and 3OA · Seen Nov 2026
  • Minimum Rounds to Complete All TasksOA · Seen Nov 2026
  • Lift Total TravelOA · Seen Nov 2026

Similar questions at other companies

  • Jump Game with Prime-3 StepsUber · OAUber interview questions
  • Count Permutations Without Three Equal Parities in a RowGoogle · OAGoogle interview questions
  • Maximum Score with Prime JumpsMicrosoft · OAMicrosoft interview questions
  • Jump Game with Prime-3 StepsAgoda · OAAgoda interview questions
  • Coin Game From The EndsTekion · PHONE SCREENTekion interview questions
  • Maximum-Product Subarray with an Empty ChoiceAkuna Capital · PHONE SCREENAkuna Capital interview questions
  • Pascal's TriangleJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions
  • Largest Consistent Visiting GroupAuxoAI · OA
  • Delete and Freeze GameRubrik · OARubrik interview questions
  • Lock CodeVisa · OAVisa interview questions
All Infosys interview questionsSee Infosys hiring insights
Saved
class Solution {
    public long minimumQuadraticJumpCost(int[] positions, int[] landingCosts, int maxJumps) {
      // Write your code here.
    }

}
Checking account…