In fact, you can apply the idea from the specified topic. But since you have two changes, you have to measure two things.
For example, measure the sum of the values ββand the sum of the squares and compare them with the expected ones. If number A is duplicated and number B is missing, you will have:
- sum - expected_sum = AB
- sum_of_squares - expected_sum_of_squares = A ^ 2-B ^ 2
Having (AB) and (A ^ 2-B ^ 2), you can get (A + B) = (A ^ 2-B ^ 2) / (AB).
Having (A + B) and (AB), you can get A = (A + B) / 2 + (AB) / 2 and B = (A + B) / 2- (AB) / 2
source share