Generate a string consisting of characters ' a ' and ' b ' that satisfy the given conditions | Function to generate and print the required string ; More ' b ' , append " bba " ; More ' a ' , append " aab " ; Equal number of ' a ' and ' b ' append " ab " ; Driver code
function generateString ( A , B ) { let rt = " " ; while ( 0 < A 0 < B ) { if ( A < B ) { if ( 0 < B -- ) { rt += ( ' ' ) ; } if ( 0 < B -- ) { rt += ( ' ' ) ; } if ( 0 < A -- ) { rt += ( ' ' ) ; } } else if ( B < A ) { if ( 0 < A -- ) { rt += ( ' ' ) ; } if ( 0 < A -- ) { rt += ( ' ' ) ; } if ( 0 < B -- ) { rt += ( ' ' ) ; } } else { if ( 0 < A -- ) { rt += ( ' ' ) ; } if ( 0 < B -- ) { rt += ( ' ' ) ; } } } document . write ( rt ) ; } let A = 2 , B = 6 ; generateString ( A , B ) ;