title: Minimum Insertions Sort Array
signature: function minimum_insertions_sort_array(arr, n)
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 );
  }
question_info.entry_fn_name: minimum_insertions_sort_array
question_info.entry_cls_name: Solution
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(arr, n, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(arr, n) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver({4, 7, 20, 22, 23, 31, 33, 36, 47, 61, 63, 63, 71, 74, 82, 91, 95, 99}, 15, 0)
      print(string.format("TEST-0...%s",result))
  
      result = driver({-84, 12, -42, -78, 22, 72, 56, 70, 28, -72}, 7, 3)
      print(string.format("TEST-1...%s",result))
  
      result = driver({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)
      print(string.format("TEST-2...%s",result))
  
      result = driver({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)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-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)
      print(string.format("TEST-4...%s",result))
  
      result = driver({1, 1, 0, 1, 0, 1, 0, 0, 1, 0}, 8, 4)
      print(string.format("TEST-5...%s",result))
  
      result = driver({26, 36, 58, 64, 69, 72, 79, 82, 82, 87, 89, 90, 95}, 8, 0)
      print(string.format("TEST-6...%s",result))
  
      result = driver({-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)
      print(string.format("TEST-7...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 10, 0)
      print(string.format("TEST-8...%s",result))
  
      result = driver({36, 62, 58, 24, 99, 12, 46, 3, 4, 40, 54, 97, 48, 94, 98, 7, 17, 5, 3, 36, 3}, 16, 10)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.test_list: [{"idx": 0, "outputs": 0, "inputs": {"arr": [4, 7, 20, 22, 23, 31, 33, 36, 47, 61, 63, 63, 71, 74, 82, 91, 95, 99], "n": 15}}, {"idx": 1, "outputs": 3, "inputs": {"arr": [-84, 12, -42, -78, 22, 72, 56, 70, 28, -72], "n": 7}}, {"idx": 2, "outputs": 0, "inputs": {"arr": [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], "n": 16}}, {"idx": 3, "outputs": 7, "inputs": {"arr": [29, 41, 4, 62, 77, 74, 30, 2, 14, 90, 93, 10, 78, 36, 66, 22, 48, 89, 36, 73, 70, 23, 90], "n": 13}}, {"idx": 4, "outputs": 0, "inputs": {"arr": [-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], "n": 36}}, {"idx": 5, "outputs": 4, "inputs": {"arr": [1, 1, 0, 1, 0, 1, 0, 0, 1, 0], "n": 8}}, {"idx": 6, "outputs": 0, "inputs": {"arr": [26, 36, 58, 64, 69, 72, 79, 82, 82, 87, 89, 90, 95], "n": 8}}, {"idx": 7, "outputs": 30, "inputs": {"arr": [-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], "n": 41}}, {"idx": 8, "outputs": 0, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 10}}, {"idx": 9, "outputs": 10, "inputs": {"arr": [36, 62, 58, 24, 99, 12, 46, 3, 4, 40, 54, 97, 48, 94, 98, 7, 17, 5, 3, 36, 3], "n": 16}}]