What if you need both the minimum AND second minimum in a range?
Store pairs at each position: .
Merge function:
def merge(pair1, pair2):
a, b = pair1 # min, secondMin from first range
c, d = pair2 # min, secondMin from second range
sorted_vals = sorted([a, b, c, d])
return (sorted_vals[0], sorted_vals[1])
This still allows queries because the merge is idempotent on the pair structure.
Use case: problems needing the two smallest elements in a range, or detecting ties.