title: Minimum Insertions Sort Array
signature: minimum_insertions_sort_array <- 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(4L, 7L, 20L, 22L, 23L, 31L, 33L, 36L, 47L, 61L, 63L, 63L, 71L, 74L, 82L, 91L, 95L, 99L), 15L, 
          0L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-84L, 12L, -42L, -78L, 22L, 72L, 56L, 70L, 28L, -72L), 7L, 
          3L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(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), 16L, 
          0L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(29L, 41L, 4L, 62L, 77L, 74L, 30L, 2L, 14L, 90L, 93L, 10L, 78L, 36L, 66L, 22L, 48L, 89L, 36L, 73L, 70L, 23L, 90L), 13L, 
          7L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-80L, -72L, -68L, -66L, -58L, -50L, -48L, -32L, -28L, -24L, -22L, -18L, 0L, 2L, 6L, 10L, 12L, 14L, 14L, 18L, 24L, 24L, 24L, 28L, 28L, 28L, 34L, 38L, 42L, 42L, 46L, 46L, 46L, 58L, 80L, 82L, 82L, 84L, 84L, 86L, 88L, 90L, 92L, 96L), 36L, 
          0L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, 0L), 8L, 
          4L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(26L, 36L, 58L, 64L, 69L, 72L, 79L, 82L, 82L, 87L, 89L, 90L, 95L), 8L, 
          0L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-52L, -40L, 98L, 40L, 42L, -50L, 60L, -64L, -92L, 36L, -88L, 72L, -72L, 38L, -80L, -52L, 68L, 70L, 16L, 22L, -30L, -74L, 56L, -80L, 62L, -54L, -32L, -22L, -86L, -70L, 88L, -76L, -46L, 28L, 40L, -2L, -84L, 68L, -98L, -16L, 90L, 36L, -38L, -86L, 20L, -40L, 82L, 98L, 54L), 41L, 
          30L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 10L, 
          0L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(36L, 62L, 58L, 24L, 99L, 12L, 46L, 3L, 4L, 40L, 54L, 97L, 48L, 94L, 98L, 7L, 17L, 5L, 3L, 36L, 3L), 16L, 
          10L
      )))
  
  }
  
  main()
source_py: def minimum_insertions_sort_array(arr, N):
      lis = ([0] * N)
      for i in range(N):
          lis[i] = 1
      for i in range(1, N):
          for j in range(i):
              if ((arr[i] >= arr[j]) and (lis[i] < (lis[j] + 1))):
                  lis[i] = (lis[j] + 1)
      max = 0
      for i in range(N):
          if (max < lis[i]):
              max = lis[i]
      return (N - max)
source_cpp: int minimum_insertions_sort_array(vector<int> arr, int N) {
    int lis [ N ];
    for ( int i = 0;
    i < N;
    i ++ ) lis [ i ] = 1;
    for ( int i = 1;
    i < N;
    i ++ ) for ( int j = 0;
    j < i;
    j ++ ) if ( arr [ i ] >= arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1;
    int max = 0;
    for ( int i = 0;
    i < N;
    i ++ ) if ( max < lis [ i ] ) max = lis [ i ];
    return ( N - max );
  }