title: Minimum Insertions Sort Array
signature: class Solution {
  
      public int MinimumInsertionsSortArray(List<int> arr, int n) {
test_code: using System;
  using System.Numerics;
  using System.Diagnostics;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Security.Cryptography;
  using System.Web.UI;
  using System.Web.Script.Serialization;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  namespace EvaluatePrediction {
      class TestRunner {
          public bool ValidateSolution(int actual, int expected){
              return new JavaScriptSerializer().Serialize(actual) == new JavaScriptSerializer().Serialize(expected);
          }
  
          public string driver(List<int> arr, int n, int expected){
              try{
                PLACEHOLDER_CLS_NAME solution_cls = new PLACEHOLDER_CLS_NAME();
                int pred_result = solution_cls.PLACEHOLDER_FN_NAME(arr, n); 
                if (ValidateSolution(
                      pred_result,
                      expected)){
                  return "PASSED";
                }
                return "FAILED";
              } 
              catch (Exception exception_obj)
              {
                return exception_obj.GetType().FullName;
              }
          }
          static void Main(string[] args) {
              TestRunner runner = new TestRunner();
              String result;
              result = runner.driver(
                  new List<int>{4, 7, 20, 22, 23, 31, 33, 36, 47, 61, 63, 63, 71, 74, 82, 91, 95, 99}, 15, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-0...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-84, 12, -42, -78, 22, 72, 56, 70, 28, -72}, 7, 
                  3
              );
              Console.WriteLine(string.Format(
                  "TEST-1...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{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}, 16, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-2...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{29, 41, 4, 62, 77, 74, 30, 2, 14, 90, 93, 10, 78, 36, 66, 22, 48, 89, 36, 73, 70, 23, 90}, 13, 
                  7
              );
              Console.WriteLine(string.Format(
                  "TEST-3...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-80, -72, -68, -66, -58, -50, -48, -32, -28, -24, -22, -18, 0, 2, 6, 10, 12, 14, 14, 18, 24, 24, 24, 28, 28, 28, 34, 38, 42, 42, 46, 46, 46, 58, 80, 82, 82, 84, 84, 86, 88, 90, 92, 96}, 36, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-4...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{1, 1, 0, 1, 0, 1, 0, 0, 1, 0}, 8, 
                  4
              );
              Console.WriteLine(string.Format(
                  "TEST-5...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{26, 36, 58, 64, 69, 72, 79, 82, 82, 87, 89, 90, 95}, 8, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-6...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-52, -40, 98, 40, 42, -50, 60, -64, -92, 36, -88, 72, -72, 38, -80, -52, 68, 70, 16, 22, -30, -74, 56, -80, 62, -54, -32, -22, -86, -70, 88, -76, -46, 28, 40, -2, -84, 68, -98, -16, 90, 36, -38, -86, 20, -40, 82, 98, 54}, 41, 
                  30
              );
              Console.WriteLine(string.Format(
                  "TEST-7...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 10, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-8...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{36, 62, 58, 24, 99, 12, 46, 3, 4, 40, 54, 97, 48, 94, 98, 7, 17, 5, 3, 36, 3}, 16, 
                  10
              );
              Console.WriteLine(string.Format(
                  "TEST-9...{0}",
                  result)
              );
          }
      }
  }
  
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 );
  }