title: Array Element Moved K Using Single Moves
signature: array_element_moved_k_using_single_moves <- function(a, n, k) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(a, n, k, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(a, n, k), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(2L, 5L, 5L, 9L, 10L, 10L, 11L, 14L, 23L, 27L, 31L, 32L, 33L, 33L, 33L, 37L, 39L, 41L, 41L, 42L, 42L, 43L, 47L, 60L, 61L, 68L, 73L, 73L, 73L, 78L, 80L, 80L, 82L, 83L, 86L, 87L, 89L, 92L, 94L, 98L), 33L, 37L, 
          33L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(80L, -58L, 64L, 48L, -16L, 60L, -50L, -52L, 62L, -86L, -96L, 52L, 26L, -30L, 14L), 14L, 13L, 
          14L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L), 7L, 6L, 
          7L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(90L, 23L, 43L, 42L, 7L, 71L, 79L), 4L, 4L, 
          4L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-96L, -96L, -90L, -84L, -68L, -64L, -56L, -56L, -50L, -50L, -48L, -46L, -28L, -18L, 0L, 0L, 6L, 32L, 32L, 34L, 42L, 42L, 46L, 50L, 50L, 52L, 64L, 64L, 70L, 76L, 84L, 88L), 28L, 21L, 
          64L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 1L, 1L), 1L, 2L, 
          1L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(2L, 9L, 15L, 19L, 26L, 29L, 42L, 45L, 46L, 47L, 55L, 60L, 60L, 61L, 62L, 64L, 68L, 69L, 74L, 79L, 96L), 14L, 17L, 
          14L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-32L, 12L, 80L, 42L, 80L, 8L, 58L, -76L, -42L, -98L, 22L, -90L, -16L, -4L, -62L, -32L, 28L, 12L, 78L, -52L, -84L, 78L, 88L, -76L, -52L, 68L, -34L, -16L, -4L, 2L, -78L, -94L, -22L, 34L, 6L, -62L, 72L), 26L, 31L, 
          26L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(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), 26L, 14L, 
          1L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(52L, 19L), 1L, 1L, 
          1L
      )))
  
  }
  
  main()
source_py: def array_element_moved_k_using_single_moves(a, n, k):
      if (k >= (n - 1)):
          return n
      best = 0
      times = 0
      for i in range(n):
          if (a[i] > best):
              best = a[i]
              if (i == True):
                  times = 1
          else:
              times += 1
          if (times >= k):
              return best
      return best
source_cpp: int array_element_moved_k_using_single_moves(vector<int> a, int n, int k) {
    if ( k >= n - 1 ) return n;
    int best = 0, times = 0;
    for ( int i = 0;
    i < n;
    i ++ ) {
      if ( a [ i ] > best ) {
        best = a [ i ];
        if ( i ) times = 1;
      }
      else times += 1;
      if ( times >= k ) return best;
    }
    return best;
  }