Generate a sequence with the given operations | Java Implementation of above approach ; function to find minimum required permutation ; Driver code
import java . util . * ; class GFG { static void StringMatch ( String s ) { int lo = 0 , hi = s . length ( ) , len = s . length ( ) ; Vector < Integer > ans = new Vector < > ( ) ; for ( int x = 0 ; x < len ; x ++ ) { if ( s . charAt ( x ) == ' I ' ) { ans . add ( lo ) ; lo += 1 ; } else { ans . add ( hi ) ; hi -= 1 ; } } ans . add ( lo ) ; System . out . print ( " [ " ) ; for ( int i = 0 ; i < ans . size ( ) ; i ++ ) { System . out . print ( ans . get ( i ) ) ; if ( i != ans . size ( ) - 1 ) System . out . print ( " , " ) ; } System . out . print ( " ] " ) ; } public static void main ( String [ ] args ) { String S = " IDID " ; StringMatch ( S ) ; } }