title: Form Minimum Number From Given Sequence 1
signature: string formMinimumNumberFromGivenSequence1(string seq) {
test_code: #include <algorithm>
  #include <assert.h>
  #include <cstdlib>
  #include <iostream>
  #include <map>
  #include <set>
  #include <string>
  #include <tuple> 
  #include <unordered_map>
  #include <vector>
  #include <math.h>
  #include <cmath>
  #include <bits/stdc++.h>
  #include <numeric>
  #include <functional>
  
  using namespace std;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  bool validateSolution(string actual, string expected){
      return actual == expected;
  }
  
  string driver(string seq, string expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(seq), expected)){
              return "PASSED";
          }
          return "FAILED";
      }
      catch (const std::overflow_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::runtime_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::exception& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (...)
      {
          return "UNK_ERROR";
      }
  }
  
  int main() {
      string result = "";
  
      result = driver("D", "[2, 1]"); 
      cout << "TEST-" << 0 << "..."
           <<  result
           << "\n";
  
      result = driver("I", "[1, 2]"); 
      cout << "TEST-" << 1 << "..."
           <<  result
           << "\n";
  
      result = driver("DD", "[3, 2, 1]"); 
      cout << "TEST-" << 2 << "..."
           <<  result
           << "\n";
  
      result = driver("II", "[1, 2, 3]"); 
      cout << "TEST-" << 3 << "..."
           <<  result
           << "\n";
  
      result = driver("DIDI", "[2, 1, 4, 3, 5]"); 
      cout << "TEST-" << 4 << "..."
           <<  result
           << "\n";
  
      result = driver("IIDDD", "[1, 2, 6, 5, 4, 3]"); 
      cout << "TEST-" << 5 << "..."
           <<  result
           << "\n";
  
      result = driver("DDIDDIID", "[3, 2, 1, 6, 5, 4, 7, 9, 8]"); 
      cout << "TEST-" << 6 << "..."
           <<  result
           << "\n";
  
      result = driver("176297", "[7, 6, 5, 4, 3, 2, 1]"); 
      cout << "TEST-" << 7 << "..."
           <<  result
           << "\n";
  
      result = driver("1", "[2, 1]"); 
      cout << "TEST-" << 8 << "..."
           <<  result
           << "\n";
  
      result = driver("XHkhZq", "[7, 6, 5, 4, 3, 2, 1]"); 
      cout << "TEST-" << 9 << "..."
           <<  result
           << "\n";
  
      return 0;
  }
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;
  }