FastPrepBinary Tree Preorder Traversal with O(1) Auxiliary Space
Problems/Binary Tree Preorder Traversal with O(1) Auxiliary Space

Binary Tree Preorder Traversal with O(1) Auxiliary Space

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Bloomberg new grad phone screen. It asks directly for Morris preorder traversal with no extra data structure. Our version is about 100% the same as the reported question.

Given the root of a binary tree, return its preorder traversal values: root, then left subtree, then right subtree.

Use Morris traversal so the algorithm uses O(1) auxiliary space apart from the returned array. Every temporary pointer must be restored before returning.

Function

preorderTraversal(root: TreeNode) → List<Integer>

Examples

Example 1

root = [1,null,2,3]return = [1,2,3]
root
123

Visit the root, then the right subtree whose left child is three.

Example 2

root = []return = []
root
empty

An empty tree has an empty traversal.

Constraints

  • The tree contains between 0 and 10^5 nodes.
  • -10^9 <= Node.val <= 10^9.

More Bloomberg LP Phone Screen questions

  • Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • 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
  • Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
  • Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
  • Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
  • Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Lowest Common Ancestor in a BST and a Binary TreeGreyOrange · PHONE SCREENGreyOrange interview questions
  • Path Between Two Nodes of a Fibonacci TreeDatabricks · PHONE SCREEN · ONSITE INTERVIEWDatabricks interview questions
  • Convert a Sorted Linked List to a Balanced BSTMeta · PHONE SCREENMeta interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • House Robber IIIOkta · PHONE SCREENOkta interview questions
  • Lowest Common Ancestor in an N-ary TreeGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Render a Task Tree from CSV RowsStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
  • Validate Binary Search TreeKotak Mahindra Bank · PHONE SCREENKotak Mahindra Bank interview questions
  • House Robber IIIGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
  • Binary Tree Target-Sum PathsByteDance · PHONE SCREENByteDance interview questions

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)
  • Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
  • Bloomberg New Grad Coding Questions: 121 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 List<Integer> preorderTraversal(TreeNode root) {
        // Write your code here.
    }

}
Checking account…