Code Room
CodingMediumcod-g1486
Subject Dynamic programming 1dLevel Entry–Mid~14 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

A hopscotch course for a game level is a row of stones, each with a height. Your character starts on the first stone and must reach the last one, hopping either to the next stone or over one stone to the stone after it. A hop from stone i to stone j costs the absolute height difference between them. Given the heights (at least one stone), return the minimum total cost to reach the last stone. For example, [10, 30, 40, 20] costs 30.

Implement
min_hop_cost(heights: list[int]) → int
Examples
in[[10,30,40,20]]out30
in[[30,10,60,10,60,50]]out40
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.