FindMissingTwoNumbers

package BitMassking;

public class FindMissingTwoNumbers {
public static void main(String[] args){
int n=6;
int []arr ={1,3,4,5,6};

      int z=0;
       for(int i=0; i<arr.length;i++){
             z=z^arr[i];
       }
       for(int i=1; i<=n;i++){
            z=z^i;
       }
      // System.out.println(z);

    int set_bit=z&~(z-1);
       //System.out.println(set_bit);

    int group1=0,group2=0;
    for(int i=0; i<arr.length ; i++){
           if((arr[i]&set_bit)==set_bit){
                 group1 =group1 ^arr[i];
           }else{
               group2 =group2 ^arr[i];
           }
    }
    for(int i=1; i<=n; i++){
         if((i&set_bit)==set_bit){
       group1 =group1 ^i;
        }else{
       group2 =group2 ^i;
        }
    }
      System.out.println(" The first number missing is " +group1 );
    System.out.println(" The second number missing is " + group2 );
}

}

sir output is 2 ,0 but output 2,5 hona chaiye ,pls batao sir

@SanjeevKumarRay

your code is correct but your input array is wrong in order to get 2,5 the array should be this
int []arr ={1,3,4,6};

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.