FastPrepBST to Sorted Circular Doubly Linked List
Problems/BST to Sorted Circular Doubly Linked List

BST to Sorted Circular Doubly Linked List

Bloomberg LP logoBloomberg LP● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Bloomberg new grad onsite interview. The report names the well-known BST to circular doubly linked list problem and says the interviewer added a twist it does not describe. Since we cannot see the twist, our version keeps the standard task: convert in place to a sorted, circular, doubly linked list. Our version is about 70% the same as the reported question.

Given the root of a binary search tree with distinct values, convert the tree in place into a sorted circular doubly linked list and return the list as rows.

  • Use each node's left pointer as previous.
  • Use each node's right pointer as next.
  • Link the nodes in ascending order.
  • Join the smallest and largest nodes so the list is circular.

Do not create new list nodes. Return one row per node, in list order starting at the smallest node. Each row is [value, previousValue, nextValue]. For an empty tree, return an empty matrix. The returned rows do not count against the in-place rule.

Function

bstToCircularDoublyList(root: TreeNode) → int[][]

Examples

Example 1

root = [4,2,5,1,3]return = [[1,5,2],[2,1,3],[3,2,4],[4,3,5],[5,4,1]]
root
42135

In sorted order the values are 1,2,3,4,5. The first node's previous pointer wraps around to 5, and the last node's next pointer wraps around to 1.

Example 2

root = []return = []
root
empty

The tree is empty, so the answer is an empty matrix.

Example 3

root = [7]return = [[7,7,7]]
root
7

The only node's previous and next pointers both point back to itself.

Constraints

  • The tree contains between 0 and 100000 nodes.
  • -1000000000 <= node.val <= 1000000000.
  • All node values are distinct.
  • The input is a valid binary search tree.
  • The conversion must reuse the original tree nodes. Recursion or your own stack for the traversal is allowed.
  • The returned rows do not count against the in-place rule.

More Bloomberg LP Onsite Interview questions

  • Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
  • Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Decode StringPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Minimum Replacements to Make Two Strings AnagramsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • BST to Sorted Circular Doubly Linked ListGoogle · ONSITE INTERVIEWGoogle interview questions
  • BST to Sorted Circular Doubly Linked ListApple · ONSITE INTERVIEWApple interview questions
  • Convert a Binary Tree to a Doubly Linked ListExpedia · ONSITE INTERVIEWExpedia interview questions
  • Convert a BST to a Doubly Linked ListMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Turn a BST Into a Sorted Doubly Linked ListAdobe · PHONE SCREENAdobe interview questions
  • Diagonal Traversal of a Binary TreeAmazon · ONSITE INTERVIEW
  • Render an Org Chart and Find Skip-Level PairsSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
  • Find Leaves of a Binary TreeLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • Render a Task Tree from CSV RowsStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
  • Filter Undesired Comments and Their DescendantsReddit · PHONE SCREEN · ONSITE INTERVIEWReddit interview questions

Interview reports that mention this question

  • Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)
  • Bloomberg New Grad VOs: 32 Experiences (Part 5 of 5)

Bloomberg LP interview experiences

  • Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
  • Bloomberg SWE Intern Interview Questions: 68 Questions
  • Bloomberg Interview Questions, Level Not Reported: 65 Questions
  • Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public int[][] bstToCircularDoublyList(TreeNode root) {
        // Write your code here.
    }

}
Checking account…