2 ms·
Closed form is ((1 + 250)* 250)/2 Once you know the actual sum, you can do it either: sum all, subtract total - sum. Or with data structures: it would be a var
by XenithShade 13y ago
Closed form is ((1 + 250)* 250)/2
Once you know the actual sum, you can do it either:
sum all, subtract total - sum.
Or with data structures:
it would be a variant of the "given an array find all pairs of numbers that add up to a sum". The benefit of using the data structure approach would be that you can now find x missing numbers in the range 1 - 250.
note* the closed form might have a off by one error