title: Find The Element That Appears Once
signature: class Solution {
  
      public Integer findTheElementThatAppearsOnce(ArrayList<Integer> arr, Integer n) {
test_code: import static java.util.Map.entry;  
  import java.util.*;
  import java.lang.*;
  // TESTING CODE 
  // ============================================
  class QuestionEvaluator {
      public static String validateSolution(ArrayList<Integer> arr, Integer n, Integer expected){
          try{
              Driver driver = new Driver();
              if (driver.run(arr, n,expected)){
                  return "PASSED";
              }
              return "FAILED";
              
          } catch (Exception exception_obj){
              return exception_obj.getClass().getSimpleName();
          }
  
      }
      public static void main(String[] args) {
          String result;
          result = validateSolution(new ArrayList<>(Arrays.asList(7, 26, 26, 48, 59, 62, 66, 70, 72, 75, 76, 81, 97, 98)), 7, 72);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-42, -48, -64, -74, 56, -34, 20, 16, 34, -84, 86, 38, 56, -86, 30, -74, -96, 96, 12, 10, -46, 10, -36, 38, 34, -46, -20, 14, 12, 62, -54, 20, -82, 24, 96)), 27, -28);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 0, 1, 1)), 3, 1);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(68, 91, 61, 6, 32, 47, 76, 69, 44, 71, 29, 79, 74, 33, 44, 33, 45, 75, 43, 82, 83, 81, 95, 16, 86, 33, 69, 61, 73, 21, 54, 17, 98, 62, 14, 72, 80, 31, 56, 82, 14, 48, 76)), 38, 25);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-98, -96, -92, -62, -52, -42, -42, -26, 4, 10, 14, 38, 64, 66, 72, 74, 82)), 14, 104);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 1, 1, 1, 0, 0, 0, 1, 0, 1)), 5, 0);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(53, 63, 63)), 2, 10);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-96, -38, -26, -46, 68, -36, 20, -18, -10, 52, 40, 94, -8, -64, 82, -22)), 15, 34);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 0, 0, 0, 0, 1, 1)), 3, 0);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(99, 46, 48, 81, 27, 97, 26, 50, 77, 32, 45, 99, 46)), 12, 1);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(ArrayList<Integer> arr, Integer n, Integer expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(arr, n),expected);
      }
      
      public boolean validateSolution(Integer actual, Integer expected){
          return actual.equals(expected);
      }
  }
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
source_py: def find_the_element_that_appears_once(arr, n):
      ones = 0
      twos = 0
      for i in range(n):
          twos = (twos | (ones & arr[i]))
          ones = (ones ^ arr[i])
          common_bit_mask = (~ (ones & twos))
          ones &= common_bit_mask
          twos &= common_bit_mask
      return ones
source_cpp: int find_the_element_that_appears_once(vector<int> arr, int n) {
    int ones = 0, twos = 0;
    int common_bit_mask;
    for ( int i = 0;
    i < n;
    i ++ ) {
      twos = twos | ( ones & arr [ i ] );
      ones = ones ^ arr [ i ];
      common_bit_mask = ~ ( ones & twos );
      ones &= common_bit_mask;
      twos &= common_bit_mask;
    }
    return ones;
  }