Second distinct largest
Return the second distinct largest integer, or None if fewer than two distinct values exist.
largest, second = 3, 2
value = 5
second, largest = largest, value
print(largest, second)Reason about the state
Keep the largest and second largest distinct values while scanning. Ignore repeated maxima; sorting is unnecessary. Before writing code, identify what each variable means after one iteration. Walk through the example and explain why the next transition preserves that meaning. Then check the smallest permitted input and a case with repeated values. A correct answer follows the contract for every input, including the boundary cases in the checks. Keep any input mutation within the stated rules; return a fresh result when the task asks for one.
Your task
Return the second distinct largest integer, or None if fewer than two distinct values exist.
The explanation opens here once every check passes.