title: Array Element Moved K Using Single Moves
signature: int arrayElementMovedKUsingSingleMoves(vector<int> a, int n, int k) {
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> a, int n, int k, int expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(a, n, k), 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({2, 5, 5, 9, 10, 10, 11, 14, 23, 27, 31, 32, 33, 33, 33, 37, 39, 41, 41, 42, 42, 43, 47, 60, 61, 68, 73, 73, 73, 78, 80, 80, 82, 83, 86, 87, 89, 92, 94, 98}, 33, 37, 33); 
      cout << "TEST-" << 0 << "..."
           <<  result
           << "\n";
  
      result = driver({80, -58, 64, 48, -16, 60, -50, -52, 62, -86, -96, 52, 26, -30, 14}, 14, 13, 14); 
      cout << "TEST-" << 1 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1}, 7, 6, 7); 
      cout << "TEST-" << 2 << "..."
           <<  result
           << "\n";
  
      result = driver({90, 23, 43, 42, 7, 71, 79}, 4, 4, 4); 
      cout << "TEST-" << 3 << "..."
           <<  result
           << "\n";
  
      result = driver({-96, -96, -90, -84, -68, -64, -56, -56, -50, -50, -48, -46, -28, -18, 0, 0, 6, 32, 32, 34, 42, 42, 46, 50, 50, 52, 64, 64, 70, 76, 84, 88}, 28, 21, 64); 
      cout << "TEST-" << 4 << "..."
           <<  result
           << "\n";
  
      result = driver({1, 1, 1}, 1, 2, 1); 
      cout << "TEST-" << 5 << "..."
           <<  result
           << "\n";
  
      result = driver({2, 9, 15, 19, 26, 29, 42, 45, 46, 47, 55, 60, 60, 61, 62, 64, 68, 69, 74, 79, 96}, 14, 17, 14); 
      cout << "TEST-" << 6 << "..."
           <<  result
           << "\n";
  
      result = driver({-32, 12, 80, 42, 80, 8, 58, -76, -42, -98, 22, -90, -16, -4, -62, -32, 28, 12, 78, -52, -84, 78, 88, -76, -52, 68, -34, -16, -4, 2, -78, -94, -22, 34, 6, -62, 72}, 26, 31, 26); 
      cout << "TEST-" << 7 << "..."
           <<  result
           << "\n";
  
      result = driver({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}, 26, 14, 1); 
      cout << "TEST-" << 8 << "..."
           <<  result
           << "\n";
  
      result = driver({52, 19}, 1, 1, 1); 
      cout << "TEST-" << 9 << "..."
           <<  result
           << "\n";
  
      return 0;
  }
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;
  }