Validate parentheses and find k-th largest | Meta Interview Question