iterate through the stack Use string ( int , char ) in order to replicate the character multiple times and convert into string then add in front of output string
String ans = " " ; while ( st . size ( ) > 0 ) { char c = st . peek ( ) . c ; int cnt = st . peek ( ) . ctr ; while ( cnt -- > 0 ) ans = c + ans ; st . pop ( ) ; } return ans ; }