Generate all permutations of a string that follow given constraints | Simple C # program to print all permutations of a string that follow given constraint ; Check if current permutation is valid ; Recursively generate all permutation ; Driver code
using System ; using System . Text ; class GFG { static void permute ( StringBuilder str , int l , int r ) { if ( l == r ) { if ( str . ToString ( ) . IndexOf ( " AB " ) == - 1 ) { Console . Write ( str . ToString ( ) + " ▁ " ) ; } return ; } for ( int i = l ; i <= r ; i ++ ) { char tmp = str [ l ] ; str [ l ] = str [ i ] ; str [ i ] = tmp ; permute ( str , l + 1 , r ) ; tmp = str [ l ] ; str [ l ] = str [ i ] ; str [ i ] = tmp ; } } static void Main ( string [ ] arg ) { string str = " ABC " ; StringBuilder s = new StringBuilder ( str ) ; permute ( s , 0 , str . Length - 1 ) ; } }