← Microsoft Interview Insights

Microsoft·Software Engineer·Onsite - Coding / Algorithms·Intermediate

Intermediate
Apr 2026

Summary

Microsoft design round focused on a stock price tracker problem. Pretty standard for this kind of interview but the min/max part had more moving pieces than I expected.

Questions Asked (1)

Q1

Design a data structure that supports stock price updates (with the ability to correct past entries) and can return the current price, the maximum price, and the minimum price at any time.

Algorithms & Data StructuresSystem DesignTechnical Trade-offs
Author's notes

The update-with-correction part is what trips you up if you jump straight to an array or sorted list.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements: updates can correct past entries, and queries for current, max, and min prices must be efficient. Propose a data structure like a balanced BST or two heaps with lazy deletion, and discuss trade-offs between update and query times.

Pro tip: Mention that using a balanced BST (e.g., TreeMap in Java) allows O(log n) updates and O(1) min/max queries, but if updates are frequent and queries rare, a simpler approach like maintaining a list with periodic sorting might suffice. Always discuss trade-offs based on expected usage patterns.

1. Clarify Requirements

Ask about the frequency of updates vs. queries, the range of stock prices, and whether updates are timestamped or indexed. This determines the optimal data structure.

2. Propose Data Structures

Suggest a balanced binary search tree (e.g., TreeMap) to store price entries keyed by timestamp/index, allowing O(log n) updates and O(1) min/max via first/last entries. Alternatively, use two heaps with lazy deletion for min and max, but updates become O(log n) with potential O(n) cleanup.

3. Analyze Trade-offs

Compare time complexities: BST gives O(log n) update, O(1) min/max; heaps give O(log n) update, O(1) min/max but with lazy deletion overhead. Discuss memory and implementation complexity.

4. Handle Corrections

Explain how to update a past entry: in BST, remove old value and insert new; in heaps, mark old as invalid and insert new, cleaning up lazily. Ensure min/max queries ignore invalid entries.

5. Conclude with Recommendation

Based on typical usage (frequent updates, occasional queries), recommend a balanced BST for simplicity and guaranteed performance, or a heap-based approach if memory is constrained.

Key Points to Mention

  • Balanced BST (e.g., TreeMap) provides O(log n) updates and O(1) min/max queries.
  • Two heaps with lazy deletion can achieve similar complexities but require careful invalidation.
  • Corrections to past entries require removing the old value and inserting the new one.
  • Trade-offs: BST is simpler and more predictable; heaps may be more memory-efficient for certain patterns.
  • Consider using a hash map to track current values for quick lookups during corrections.
  • Discuss potential concurrency issues if updates and queries happen simultaneously.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.