title: Find A Rotation With Maximum Hamming Distance
signature: function find_a_rotation_with_maximum_hamming_distance(arr, n)
source_py: def find_a_rotation_with_maximum_hamming_distance(arr, n):
      brr = ([0] * ((2 * n) + 1))
      for i in range(n):
          brr[i] = arr[i]
      for i in range(n):
          brr[(n + i)] = arr[i]
      maxHam = 0
      for i in range(1, n):
          currHam = 0
          k = 0
          for j in range(i, (i + n)):
              if (brr[j] != arr[k]):
                  currHam += 1
                  k = (k + 1)
          if (currHam == n):
              return n
          maxHam = max(maxHam, currHam)
      return maxHam
source_cpp: int find_a_rotation_with_maximum_hamming_distance(vector<int> arr, int n) {
    int brr [ 2 * n + 1 ];
    for ( int i = 0;
    i < n;
    i ++ ) brr [ i ] = arr [ i ];
    for ( int i = 0;
    i < n;
    i ++ ) brr [ n + i ] = arr [ i ];
    int maxHam = 0;
    for ( int i = 1;
    i < n;
    i ++ ) {
      int currHam = 0;
      for ( int j = i, k = 0;
      j < ( i + n );
      j ++, k ++ ) if ( brr [ j ] != arr [ k ] ) currHam ++;
      if ( currHam == n ) return n;
      maxHam = max ( maxHam, currHam );
    }
    return maxHam;
  }
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({1, 4, 18, 22, 28, 34, 35, 39, 44, 45, 67, 73, 75, 79, 81, 83, 89, 93, 96}, 12, 12)
      print(string.format("TEST-0...%s",result))
  
      result = driver({52, -28}, 1, 0)
      print(string.format("TEST-1...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 21, 1)
      print(string.format("TEST-2...%s",result))
  
      result = driver({24}, 0, 0)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-68, 14, 36, 62}, 2, 2)
      print(string.format("TEST-4...%s",result))
  
      result = driver({1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0}, 12, 6)
      print(string.format("TEST-5...%s",result))
  
      result = driver({7, 10, 19, 22, 24, 28, 29, 39, 46, 55, 62, 66, 68, 73, 74, 76, 83, 84, 85, 99}, 15, 15)
      print(string.format("TEST-6...%s",result))
  
      result = driver({-38, 56, 86, 12, 24, -90, -20, -46, 38, 92, -44, -74, 54, 50, 46, 50, -94, 64, 32, -84, 70}, 14, 14)
      print(string.format("TEST-7...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1}, 8, 2)
      print(string.format("TEST-8...%s",result))
  
      result = driver({61, 89, 8}, 2, 2)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 12, "inputs": {"arr": [1, 4, 18, 22, 28, 34, 35, 39, 44, 45, 67, 73, 75, 79, 81, 83, 89, 93, 96], "n": 12}}, {"idx": 1, "outputs": 0, "inputs": {"arr": [52, -28], "n": 1}}, {"idx": 2, "outputs": 1, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 21}}, {"idx": 3, "outputs": 0, "inputs": {"arr": [24], "n": 0}}, {"idx": 4, "outputs": 2, "inputs": {"arr": [-68, 14, 36, 62], "n": 2}}, {"idx": 5, "outputs": 6, "inputs": {"arr": [1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0], "n": 12}}, {"idx": 6, "outputs": 15, "inputs": {"arr": [7, 10, 19, 22, 24, 28, 29, 39, 46, 55, 62, 66, 68, 73, 74, 76, 83, 84, 85, 99], "n": 15}}, {"idx": 7, "outputs": 14, "inputs": {"arr": [-38, 56, 86, 12, 24, -90, -20, -46, 38, 92, -44, -74, 54, 50, 46, 50, -94, 64, 32, -84, 70], "n": 14}}, {"idx": 8, "outputs": 2, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1], "n": 8}}, {"idx": 9, "outputs": 2, "inputs": {"arr": [61, 89, 8], "n": 2}}]
question_info.extension: lua
question_info.entry_fn_name: find_a_rotation_with_maximum_hamming_distance
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: lua __FILENAME__