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
let ans = " " ; while ( st . length > 0 ) { let c = st [ st . length - 1 ] . c ; let cnt = st [ st . length - 1 ] . ctr ; while ( cnt -- > 0 ) ans = c + ans ; st . pop ( ) ; } return ans ; }