Validate whether brackets are properly nested | Bloomberg Interview Question