You are building a versioned datastore with PUT(docId, contents, timestamp) and GET(docId, timestamp) returning the content of the version just before the timestamp (empty string if none). PUT timestamps can arrive unordered.
Asked in the DSA round stage. The session lasted 1 hour, and the candidate used a BST. Code was run on test cases.
Implement process_operations(operations). Each operation is either ["PUT", docId, contents, timestamp] or ["GET", docId, timestamp]. Return an array containing the result of each GET, in order. A version qualifies only when its timestamp is strictly less than the query timestamp. If multiple PUT operations use the same document and timestamp, the latest PUT replaces the previous contents.
def process_operations(operations):