• + 0 comments

    When xor same elements eliminate 2 ^ 3 ^ 2 ^ 3 ^ 6 = 6 First write examples and try solve step by step and you will see the big picture.

        public static int sansaXor(List<Integer> arr) {
            int n = arr.size();
            int ans = 0;
            if(n % 2 != 0){
                for(int i = 0; i < arr.size(); i+=2)
                    ans ^= arr.get(i); 
    								
                return ans;
    						
            }else
                return 0;
        }