Amazon interview question

K closest element Generate all valid parenthesis