Your question is Balanced Brackets and List Merge. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
PagerDuty configuration and incident-routing expressions can contain nested brackets. Given a bracket string and two sorted integer lists, first verify that the brackets are properly matched and nested. If they are valid, return one sorted list containing all values from both input lists. If the bracket string is invalid, return None and do not merge the lists.
The bracket string contains only (, ), [, ], {, and }. An empty string is valid. The input lists are sorted in nondecreasing order and may contain duplicates.
Implement validate_and_merge(brackets, first, second):
brackets, a string; first and second, sorted lists of integers.brackets is valid, otherwise None.def validate_and_merge(brackets, first, second):