title: Find The Element That Appears Once
signature: function find_the_element_that_appears_once(arr, n)
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;
  }
question_info.entry_fn_name: find_the_element_that_appears_once
question_info.entry_cls_name: Solution
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(arr, n, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(arr, n) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver({7, 26, 26, 48, 59, 62, 66, 70, 72, 75, 76, 81, 97, 98}, 7, 72)
      print(string.format("TEST-0...%s",result))
  
      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)
      print(string.format("TEST-1...%s",result))
  
      result = driver({0, 0, 1, 1}, 3, 1)
      print(string.format("TEST-2...%s",result))
  
      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)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-98, -96, -92, -62, -52, -42, -42, -26, 4, 10, 14, 38, 64, 66, 72, 74, 82}, 14, 104)
      print(string.format("TEST-4...%s",result))
  
      result = driver({0, 1, 1, 1, 0, 0, 0, 1, 0, 1}, 5, 0)
      print(string.format("TEST-5...%s",result))
  
      result = driver({53, 63, 63}, 2, 10)
      print(string.format("TEST-6...%s",result))
  
      result = driver({-96, -38, -26, -46, 68, -36, 20, -18, -10, 52, 40, 94, -8, -64, 82, -22}, 15, 34)
      print(string.format("TEST-7...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 1, 1}, 3, 0)
      print(string.format("TEST-8...%s",result))
  
      result = driver({99, 46, 48, 81, 27, 97, 26, 50, 77, 32, 45, 99, 46}, 12, 1)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.test_list: [{"idx": 0, "outputs": 72, "inputs": {"arr": [7, 26, 26, 48, 59, 62, 66, 70, 72, 75, 76, 81, 97, 98], "n": 7}}, {"idx": 1, "outputs": -28, "inputs": {"arr": [-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], "n": 27}}, {"idx": 2, "outputs": 1, "inputs": {"arr": [0, 0, 1, 1], "n": 3}}, {"idx": 3, "outputs": 25, "inputs": {"arr": [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], "n": 38}}, {"idx": 4, "outputs": 104, "inputs": {"arr": [-98, -96, -92, -62, -52, -42, -42, -26, 4, 10, 14, 38, 64, 66, 72, 74, 82], "n": 14}}, {"idx": 5, "outputs": 0, "inputs": {"arr": [0, 1, 1, 1, 0, 0, 0, 1, 0, 1], "n": 5}}, {"idx": 6, "outputs": 10, "inputs": {"arr": [53, 63, 63], "n": 2}}, {"idx": 7, "outputs": 34, "inputs": {"arr": [-96, -38, -26, -46, 68, -36, 20, -18, -10, 52, 40, 94, -8, -64, 82, -22], "n": 15}}, {"idx": 8, "outputs": 0, "inputs": {"arr": [0, 0, 0, 0, 0, 1, 1], "n": 3}}, {"idx": 9, "outputs": 1, "inputs": {"arr": [99, 46, 48, 81, 27, 97, 26, 50, 77, 32, 45, 99, 46], "n": 12}}]