Function to find the lexicographically next balanced bracket expression if possible
function next_balanced_sequence ( s ) { let next = " " ; let length = s . length ; let depth = 0 ; for ( let i = length - 1 ; i >= 0 ; -- i ) {