Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Store an AVL Tree

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

Your question is Store an AVL 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

How would you store an AVL tree?

Implement serialize_avl(root) to encode the tree structure using preorder traversal and None markers for missing children. The input is a nested list [key, left, right], or None for an empty tree. Return a flat list that preserves every key and child relationship, including the empty tree case.

Constraints

  • 0 <= number of nodes <= 10^4
  • Each key is an integer
  • Keys are unique
  • The input tree satisfies the binary-search-tree ordering property
  • The input tree is AVL-balanced

Function Signature

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