PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates understanding of binary search tree properties, in-order traversal, in-place pointer manipulation, and algorithmic complexity when converting tree nodes into a sorted doubly linked list.

  • Medium
  • Meta
  • Coding & Algorithms
  • Software Engineer

Convert BST to sorted doubly list

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

Convert a binary search tree into a sorted doubly linked list in-place. Reuse the existing tree nodes: the left pointer becomes prev and the right pointer becomes next. Do not allocate new nodes. Return the head of the doubly linked list. Ensure the list is sorted in nondecreasing order according to an in-order traversal, and specify how you handle duplicate keys. Provide both a recursive and an iterative solution, and analyze time and space complexity. Follow-ups: ( 1) Modify your solution to produce a circular doubly linked list. ( 2) If recursion is forbidden, how do you guarantee O( 1) auxiliary space aside from the output pointers (e.g., Morris traversal)?

Quick Answer: This question evaluates understanding of binary search tree properties, in-order traversal, in-place pointer manipulation, and algorithmic complexity when converting tree nodes into a sorted doubly linked list.

Given BST level-order values, return the sorted values that the in-place doubly linked list would contain.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: ([4,2,5,1,3],)

Expected Output: [1, 2, 3, 4, 5]

Explanation: In-order list.

Input: ([],)

Expected Output: []

Explanation: Empty tree.

Input: ([1],)

Expected Output: [1]

Explanation: Single node.

Hints

  1. Model object-style prompts as arrays or operation streams when needed.
  2. Handle empty and boundary cases before the main logic.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ 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
  • AI Coding 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.

Related Coding Questions

  • Find Shortest Unique Prefixes - Meta (medium)
  • Compute Exclusive Execution Times - Meta (medium)
  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)