My first instinct was to just filter by dasherId and count ACCEPTEDs, which is wrong because you have to subtract out the ones that got FULFILLED or CANCELED afterward.
Clarify the problem constraints (e.g., stream processing, memory limits, multiple events per order) and then propose a solution using a hash map to track ongoing deliveries per dasher. For each event, update the dasher's ongoing count based on the status, and compute pay as ongoing count * 0.3. Discuss trade-offs between real-time processing and batch processing.
Pro tip: Emphasize that the solution should handle out-of-order events and duplicate events gracefully, as real-world streams often have these issues. Mention that you would use a sliding window or session window if the stream is unbounded.
Ask about the stream's nature (ordered vs. unordered, duplicates), memory limits, and whether pay should be computed in real-time or on-demand. Confirm the definition of 'ongoing' and how to handle multiple events for the same order.
Use a hash map to store the set of ongoing order IDs for each dasher, and another map to track the status of each order to avoid double-counting. Alternatively, maintain a count per dasher if we can assume events are processed in order.
For each event, if status is ACCEPTED, add the order ID to the dasher's ongoing set; if FULFILLED or CANCELED, remove it. Update the dasher's ongoing count accordingly.
For a given dasher ID, return the size of their ongoing set multiplied by 0.3. If using a count, simply return count * 0.3.
Address handling of out-of-order events (e.g., FULFILLED before ACCEPTED), duplicates, and memory usage. Propose solutions like event-time processing with watermarks or using a database for persistence.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.