public class Solution {
public static int[] findMissingRepeatingNumbers(int []arr) {
// Write your code here
// X -> repeating , Y -> missing (assume)
// Sn -> sum of first n numbers
// S -> sum of all numbers
// S - Sn = X - Y = val1
// Sn2 -> square of first n numbers
// S2 -> sum of sq of all numbers
// S2 - Sn2 = X2 - Y2
// = (X + Y)(X - Y)
// X + Y = (S2 - Sn2)/(X - Y) = val2
// X + Y = val2
// + X - Y = val1
// 2X = val2 + val1
// X = (val2 + val1)/2..... Y = val2 - X
int sn = 0,s = 0,sn2 = 0,s2 = 0,x,y,val1,val2;
for(int i=1;i<=arr.length;i++){
sn+=i;
sn2+=(i*i);
}
for(int a:arr){
s+=a;
s2+=(a*a);
}
val1 = s - sn;
val2 = (s2 - sn2)/val1;
x = (val2 + val1)/2;
y = val2 - x;
int[] ans = new int[2];
ans[0] = x;
ans[1] = y;
return ans;
}
}