title: Form Minimum Number From Given Sequence 1
signature: function form_minimum_number_from_given_sequence_1(seq)
test_code: using Printf
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  function validate_solution(actual, expected)
      return actual == expected
  end
  
  function driver(seq, expected)
      try
  
          if validate_solution(PLACEHOLDER_FN_NAME(seq), expected)
              return "PASSED";
          end
          return "FAILED";
      catch exception_obj
          return string(Base.typename(typeof(exception_obj)).wrapper);
      end
  end
  
  function main()
      
      result = driver("D", "[2, 1]");
      @printf("TEST-0...%s\n",result);
      
      result = driver("I", "[1, 2]");
      @printf("TEST-1...%s\n",result);
      
      result = driver("DD", "[3, 2, 1]");
      @printf("TEST-2...%s\n",result);
      
      result = driver("II", "[1, 2, 3]");
      @printf("TEST-3...%s\n",result);
      
      result = driver("DIDI", "[2, 1, 4, 3, 5]");
      @printf("TEST-4...%s\n",result);
      
      result = driver("IIDDD", "[1, 2, 6, 5, 4, 3]");
      @printf("TEST-5...%s\n",result);
      
      result = driver("DDIDDIID", "[3, 2, 1, 6, 5, 4, 7, 9, 8]");
      @printf("TEST-6...%s\n",result);
      
      result = driver("176297", "[7, 6, 5, 4, 3, 2, 1]");
      @printf("TEST-7...%s\n",result);
      
      result = driver("1", "[2, 1]");
      @printf("TEST-8...%s\n",result);
      
      result = driver("XHkhZq", "[7, 6, 5, 4, 3, 2, 1]");
      @printf("TEST-9...%s\n",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;
  }