Interview Questions/Coding/Live Exchange Feed Audit

Live Exchange Feed Audit

Preview mode. Log in to edit, run, submit, and save progress.

Medium

Live Exchange Feed Audit

A live exchange feed receives price update and query events. Each event has three integer fields: operation type, timestamp, and price. When the operation type is 1, the event writes or corrects the price at that timestamp. A timestamp may be updated more than once, and only the latest correction for that timestamp should count. Operation type 2 asks for the price at the latest timestamp seen so far. Operation type 3 asks for the current maximum price. Operation type 4 asks for the current minimum price. For query events, the timestamp and price fields are placeholders. Input Format: You are given an array events, where each event is [op, timestamp, price]. Output Format: Return the answers to all query events in the order they appear.

Examples

Example 1
Input:
events = [[1, 1, 10], [1, 2, 5], [2, 0, 0], [3, 0, 0], [4, 0, 0], [1, 1, 3], [3, 0, 0], [4, 0, 0], [2, 0, 0]]
Output:
5 10 5 5 3 5

Explanation: The query results in order are current=5, max=10, min=5, max=5, min=3, current=5. Printed as values, they give 5 10 5 5 3 5.

Approach hint

A corrected timestamp can leave stale entries in heaps.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

solution.cpp