Your question is Sorting Algorithm Problem. 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.
Bentley iTwin services receive model update records that must be processed in a deterministic order. Implement a stable merge sort to order updates by priority, timestamp, and element identifier.
Each update is represented as a dictionary with keys element_id, priority, and timestamp. Return a new list without modifying the input. Sort using these rules, in order:
priority values come first.timestamp values come first.element_id values come first.Do not call Python's built-in sorted() or .sort(). Your implementation should use merge sort and may define helper functions.
Implement sort_model_updates(updates), where updates is a list of dictionaries. Return a new list containing the same dictionaries in the required order. Timestamps are integers, and priorities are integers.
def sort_model_updates(updates):