3 ms·
You can prove that this algorithm works for both of those cases. Assuming min <= max: If a < min, then the sorted array is [a, min, max]. The median is min, wh
by mc10 6y ago
You can prove that this algorithm works for both of those cases. Assuming min <= max:
If a < min, then the sorted array is [a, min, max].
The median is min, which is a clamped to min.
If a > max, then the sorted array is [min, max, a].
The median is max, which is a clamped to max.