title: Find The Element That Appears Once
signature: int findTheElementThatAppearsOnce(vector<int> arr, int n) {
test_code: #include <algorithm>
  #include <assert.h>
  #include <cstdlib>
  #include <iostream>
  #include <map>
  #include <set>
  #include <string>
  #include <tuple> 
  #include <unordered_map>
  #include <vector>
  #include <math.h>
  #include <cmath>
  #include <bits/stdc++.h>
  #include <numeric>
  #include <functional>
  
  using namespace std;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  bool validateSolution(int actual, int expected){
      return actual == expected;
  }
  
  string driver(vector<int> arr, int n, int expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){
              return "PASSED";
          }
          return "FAILED";
      }
      catch (const std::overflow_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::runtime_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::exception& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (...)
      {
          return "UNK_ERROR";
      }
  }
  
  int main() {
      string result = "";
  
      result = driver({7, 26, 26, 48, 59, 62, 66, 70, 72, 75, 76, 81, 97, 98}, 7, 72); 
      cout << "TEST-" << 0 << "..."
           <<  result
           << "\n";
  
      result = driver({-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); 
      cout << "TEST-" << 1 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 0, 1, 1}, 3, 1); 
      cout << "TEST-" << 2 << "..."
           <<  result
           << "\n";
  
      result = driver({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); 
      cout << "TEST-" << 3 << "..."
           <<  result
           << "\n";
  
      result = driver({-98, -96, -92, -62, -52, -42, -42, -26, 4, 10, 14, 38, 64, 66, 72, 74, 82}, 14, 104); 
      cout << "TEST-" << 4 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 1, 1, 1, 0, 0, 0, 1, 0, 1}, 5, 0); 
      cout << "TEST-" << 5 << "..."
           <<  result
           << "\n";
  
      result = driver({53, 63, 63}, 2, 10); 
      cout << "TEST-" << 6 << "..."
           <<  result
           << "\n";
  
      result = driver({-96, -38, -26, -46, 68, -36, 20, -18, -10, 52, 40, 94, -8, -64, 82, -22}, 15, 34); 
      cout << "TEST-" << 7 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 0, 0, 0, 0, 1, 1}, 3, 0); 
      cout << "TEST-" << 8 << "..."
           <<  result
           << "\n";
  
      result = driver({99, 46, 48, 81, 27, 97, 26, 50, 77, 32, 45, 99, 46}, 12, 1); 
      cout << "TEST-" << 9 << "..."
           <<  result
           << "\n";
  
      return 0;
  }
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;
  }