title: Form Minimum Number From Given Sequence 1
signature: function form_minimum_number_from_given_sequence_1(seq)
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(seq, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(seq) 
      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("D", "[2, 1]")
      print(string.format("TEST-0...%s",result))
  
      result = driver("I", "[1, 2]")
      print(string.format("TEST-1...%s",result))
  
      result = driver("DD", "[3, 2, 1]")
      print(string.format("TEST-2...%s",result))
  
      result = driver("II", "[1, 2, 3]")
      print(string.format("TEST-3...%s",result))
  
      result = driver("DIDI", "[2, 1, 4, 3, 5]")
      print(string.format("TEST-4...%s",result))
  
      result = driver("IIDDD", "[1, 2, 6, 5, 4, 3]")
      print(string.format("TEST-5...%s",result))
  
      result = driver("DDIDDIID", "[3, 2, 1, 6, 5, 4, 7, 9, 8]")
      print(string.format("TEST-6...%s",result))
  
      result = driver("176297", "[7, 6, 5, 4, 3, 2, 1]")
      print(string.format("TEST-7...%s",result))
  
      result = driver("1", "[2, 1]")
      print(string.format("TEST-8...%s",result))
  
      result = driver("XHkhZq", "[7, 6, 5, 4, 3, 2, 1]")
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
source_py: def form_minimum_number_from_given_sequence_1(seq):
      n = len(seq)
      if (n >= 9):
          return '-1'
      result = ([None] * (n + 1))
      count = 1
      for i in range((n + 1)):
          if ((i == n) or (seq[i] == 'I')):
              for j in range((i - 1), (- 2), (- 1)):
                  result[(j + 1)] = int(('0' + str(count)))
                  count += 1
                  if ((j >= 0) and (seq[j] == 'I')):
                      break
      return result
source_cpp: string form_minimum_number_from_given_sequence_1(string seq) {
    int n = seq . length ( );
    if ( n >= 9 ) return "-1";
    string result ( n + 1, ' ' );
    int count = 1;
    for ( int i = 0;
    i <= n;
    i ++ ) {
      if ( i == n || seq [ i ] == 'I' ) {
        for ( int j = i - 1;
        j >= - 1;
        j -- ) {
          result [ j + 1 ] = '0' + count ++;
          if ( j >= 0 && seq [ j ] == 'I' ) break;
        }
      }
    }
    return result;
  }