Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Implement a Binary Search Tree

HardPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Implement a Binary Search Tree. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Demonstrate how you would implement a binary search tree.

Implement insertion, search, deletion, and inorder traversal. Duplicate values should be ignored. The function receives initial values and operations, then returns the final inorder traversal and results for every search operation.

Signature: def implement_bst(values, operations):

values is a list of integers. Each operation is a dictionary such as {"type": "insert", "value": 8}, {"type": "delete", "value": 8}, or {"type": "search", "value": 8}. Return {"inorder": [...], "search": [...]}.

Constraints

  • 0 <= values.length <= 10^4
  • 0 <= operations.length <= 10^4
  • -10^9 <= values[i], operation.value <= 10^9
  • Each operation type is one of "insert", "delete", or "search"
  • Duplicate values are ignored

Function Signature

def implement_bst(values, operations):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output