Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Store an AVL Tree
00:00
5 left

Store an AVL Tree

MediumPython

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):
Interviewer

Your question is Store an AVL Tree. Start with the requirements in the Question tab.

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.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.