FastPrepBinary Search Tree Operations
Problems/Binary Search Tree Operations

Binary Search Tree Operations

Citadel logoCitadel● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Citadel new grad phone screen. The report asks for BST insert, search, and delete, then follow-ups on the worst case and on AVL and red-black trees. We chose how duplicates work, the finite list of operations, the limits, and the examples. Our version is about 95% the same as the reported question.

Process a sequence of operations on an initially empty set of integer keys. This exercise practices implementing a binary search tree from scratch.

  • [0, key]: insert key. If it already exists, leave the set unchanged.
  • [1, key]: search for key. Append 1 if it exists, otherwise append 0.
  • [2, key]: delete key. If it is absent, leave the set unchanged.

Return the search results in operation order. Inserts and deletes produce no output. Do not use a library ordered-set or tree-map container.

Follow-up discussion

State the cost of each operation in terms of tree height. Explain how sorted insertions can produce a chain and how AVL or red-black balancing would improve the worst case. The judged exercise does not require balancing.

Function

bstOperations(operations: int[][]) → int[]

Examples

Example 1

operations = [[0,5],[0,3],[0,7],[1,3],[2,5],[1,5],[1,7]]return = [1,0,1]

After the first three inserts, the keys are 3, 5, and 7. Searching for 3 succeeds. Deleting 5 removes only that key, so searching for 5 fails and searching for 7 succeeds.

Example 2

operations = [[0,2],[0,2],[2,9],[1,2],[2,2],[1,2]]return = [1,0]

Inserting 2 twice still stores one key. Deleting the absent key 9 changes nothing. The searches before and after deleting 2 return 1 and 0.

Constraints

  • 0 <= operations.length <= 5000.
  • Each operation has exactly two integers.
  • The operation code is 0, 1, or 2.
  • -10^9 <= key <= 10^9.

More Citadel Phone Screen questions

  • Portfolio Tickers with Constant-Time Random PickPHONE SCREEN · Seen Nov 2026
  • Square Root FunctionPHONE SCREEN · Seen Oct 2026
  • Reachable Transfer PositionsPHONE SCREEN · Seen Oct 2026
  • Spreadsheet Formula DependenciesPHONE SCREEN · Seen Oct 2026
  • Merge Price-Delta FeedsPHONE SCREEN · Seen Sep 2026
  • Reconcile Unmatched Trades with Timestamp TolerancePHONE SCREEN · Seen Sep 2026
  • Top Ten Trades by Notional ValuePHONE SCREEN · Seen Sep 2026
  • Exchange BBO and Market-Wide NBBOPHONE SCREEN · Seen Sep 2026
  • Maximize Workday EarningsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Minimum Changes for Palindromic BlocksOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • N-ary Index-Path Encoder and DecoderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • Top K Pins with Insert and QueryPinterest · PHONE SCREENPinterest interview questions
  • Tree Selection and VisibilityJane Street · PHONE SCREENJane Street interview questions
  • Worst-Performing Ads by CTR in a Campaign TreeUber · PHONE SCREENUber interview questions
  • Search for an Element in a StreamAmazon · PHONE SCREEN
  • Build a File Tree from Streamed RecordsNextdoor · PHONE SCREENNextdoor interview questions
  • Hierarchical In-Memory File SystemClay · PHONE SCREEN
  • Throne Inheritance Without an Initial KingSnowflake · PHONE SCREENSnowflake interview questions
  • Nested Todo ListNotion · PHONE SCREEN · ONSITE INTERVIEWNotion interview questions

Interview reports that mention this question

  • Citadel SWE Intern Later Rounds and Superday: 13 Experiences

Citadel interview experiences

  • Citadel Securities Quant Researcher Intern Loop: 1 Experience
  • Citadel Securities Research Engineer Interview: 1 Experience
  • Citadel Securities SWE Intern First Round: 2 Experiences
  • Citadel Securities Experienced SWE Interviews: 1 Experience
  • Citadel SWE Intern First-Round Questions: 20 Experiences
All Citadel interview questionsSee Citadel hiring insights
Saved
class Solution {
    public int[] bstOperations(int[][] operations) {
        // Write your code here.
    }
}
Checking account…