Code RoomLast remaining value
EasyPrep Room Coding #471

Last remaining value

CodingAlgorithms & data structuresEntry–Mid~12 min

You are given a list of positive integers. Repeatedly perform this operation: take the two largest values x and y (with x >= y) out of the list; if x equals y, both disappear; otherwise put x - y back. Stop when at most one value remains. Return the final remaining value, or 0 if nothing remains. The starting list may also be empty (return 0) or hold a single value (return it). Example: values = [2, 7, 4, 1, 8, 1] gives 1.

Implement
final_value(values: list[int]) → int
Examples
in[[2,7,4,1,8,1]]out1
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.

0:00 of about 12 min
InputExpectedGot
[[2,7,4,1,8,1]]1not run yetsample