title: Find The Element That Appears Once
signature: find_the_element_that_appears_once <- function(arr, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(7L, 26L, 26L, 48L, 59L, 62L, 66L, 70L, 72L, 75L, 76L, 81L, 97L, 98L), 7L, 
          72L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-42L, -48L, -64L, -74L, 56L, -34L, 20L, 16L, 34L, -84L, 86L, 38L, 56L, -86L, 30L, -74L, -96L, 96L, 12L, 10L, -46L, 10L, -36L, 38L, 34L, -46L, -20L, 14L, 12L, 62L, -54L, 20L, -82L, 24L, 96L), 27L, 
          -28L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 1L, 1L), 3L, 
          1L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(68L, 91L, 61L, 6L, 32L, 47L, 76L, 69L, 44L, 71L, 29L, 79L, 74L, 33L, 44L, 33L, 45L, 75L, 43L, 82L, 83L, 81L, 95L, 16L, 86L, 33L, 69L, 61L, 73L, 21L, 54L, 17L, 98L, 62L, 14L, 72L, 80L, 31L, 56L, 82L, 14L, 48L, 76L), 38L, 
          25L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-98L, -96L, -92L, -62L, -52L, -42L, -42L, -26L, 4L, 10L, 14L, 38L, 64L, 66L, 72L, 74L, 82L), 14L, 
          104L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 1L), 5L, 
          0L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(53L, 63L, 63L), 2L, 
          10L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-96L, -38L, -26L, -46L, 68L, -36L, 20L, -18L, -10L, 52L, 40L, 94L, -8L, -64L, 82L, -22L), 15L, 
          34L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 1L, 1L), 3L, 
          0L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(99L, 46L, 48L, 81L, 27L, 97L, 26L, 50L, 77L, 32L, 45L, 99L, 46L), 12L, 
          1L
      )))
  
  }
  
  main()
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;
  }