PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Meta

Implement BST Iterator and Ticket Queue

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of binary search tree traversal and iterator design with amortized time and space analysis, as well as dynamic priority-queue design for maintaining ordered tickets with severity, recency, and tie-breaking rules.

  • medium
  • Meta
  • Coding & Algorithms
  • Machine Learning Engineer

Implement BST Iterator and Ticket Queue

Company: Meta

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

The coding interviews mentioned two algorithm/data-structure tasks: 1. **Implement a binary search tree iterator.** You are given the root of a binary search tree. Design an iterator that supports: - `hasNext()` -> returns whether there is another value to visit - `next()` -> returns the next smallest value in the tree The iterator must return values in ascending order. Aim for `O(h)` extra space, where `h` is the height of the tree, and amortized `O(1)` time per operation. 2. **Maintain a prioritized ticket queue with updates.** Build a data structure for support tickets. Each ticket has: - `ticket_id`: unique integer - `severity`: one of `low`, `medium`, or `high` - `t`: integer timestamp, where larger means more recent Support the following operations efficiently: - `upsert(ticket_id, severity, t)`: insert a new ticket or update an existing ticket - `get_top_ticket()`: return the highest-priority ticket Priority rules: 1. Higher severity comes first (`high > medium > low`) 2. If severity is the same, the more recent ticket (`t` larger) comes first 3. If there is still a tie, return the smaller `ticket_id` Return `-1` if no tickets exist.

Quick Answer: This question evaluates understanding of binary search tree traversal and iterator design with amortized time and space analysis, as well as dynamic priority-queue design for maintaining ordered tickets with severity, recency, and tie-breaking rules.

Related Interview Questions

  • Solve Two Backtracking Array Problems - Meta (hard)
  • Solve Array, Matrix, and Recommendation Problems - Meta (medium)
  • Find a String Containing Another - Meta (medium)
  • Solve Subarray Sum and Local Minimum - Meta (hard)
  • Validate abbreviations and brackets - Meta (medium)
Meta logo
Meta
Jan 24, 2026, 12:00 AM
Machine Learning Engineer
Onsite
Coding & Algorithms
0
0
Loading...

The coding interviews mentioned two algorithm/data-structure tasks:

  1. Implement a binary search tree iterator.
    You are given the root of a binary search tree. Design an iterator that supports:
    • hasNext() -> returns whether there is another value to visit
    • next() -> returns the next smallest value in the tree
    The iterator must return values in ascending order. Aim for O(h) extra space, where h is the height of the tree, and amortized O(1) time per operation.
  2. Maintain a prioritized ticket queue with updates.
    Build a data structure for support tickets. Each ticket has:
    • ticket_id : unique integer
    • severity : one of low , medium , or high
    • t : integer timestamp, where larger means more recent
    Support the following operations efficiently:
    • upsert(ticket_id, severity, t) : insert a new ticket or update an existing ticket
    • get_top_ticket() : return the highest-priority ticket
    Priority rules:
    1. Higher severity comes first ( high > medium > low )
    2. If severity is the same, the more recent ticket ( t larger) comes first
    3. If there is still a tie, return the smaller ticket_id
    Return -1 if no tickets exist.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Meta•More Machine Learning Engineer•Meta Machine Learning Engineer•Meta Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.