title: Find A Rotation With Maximum Hamming Distance
signature: find_a_rotation_with_maximum_hamming_distance <- 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(1L, 4L, 18L, 22L, 28L, 34L, 35L, 39L, 44L, 45L, 67L, 73L, 75L, 79L, 81L, 83L, 89L, 93L, 96L), 12L, 
          12L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(52L, -28L), 1L, 
          0L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 21L, 
          1L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(24L), 0L, 
          0L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-68L, 14L, 36L, 62L), 2L, 
          2L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 0L), 12L, 
          6L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(7L, 10L, 19L, 22L, 24L, 28L, 29L, 39L, 46L, 55L, 62L, 66L, 68L, 73L, 74L, 76L, 83L, 84L, 85L, 99L), 15L, 
          15L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-38L, 56L, 86L, 12L, 24L, -90L, -20L, -46L, 38L, 92L, -44L, -74L, 54L, 50L, 46L, 50L, -94L, 64L, 32L, -84L, 70L), 14L, 
          14L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 8L, 
          2L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(61L, 89L, 8L), 2L, 
          2L
      )))
  
  }
  
  main()
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;
  }