Hopscotch minimum cost
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]) → intExamples
in
[[10,30,40,20]]out30in
[[30,10,60,10,60,50]]out40What 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.
0:00 of about 14 min
solution.py
InputExpectedGot
[[10,30,40,20]]30not run yetsample[[30,10,60,10,60,50]]40not run yetsample