PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCareers
|Home/Coding & Algorithms/Snowflake

Transform tree with subtree sum mapping

Last updated: Mar 29, 2026

Quick Overview

The question evaluates proficiency in binary tree algorithms, subtree aggregation, traversal techniques, array-to-tree construction, and analysis of time and space complexity.

  • Medium
  • Snowflake
  • Coding & Algorithms
  • Software Engineer

Transform tree with subtree sum mapping

Company: Snowflake

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

You are given the roots of two complete binary trees T1 and T2 that have identical structure (same shape and number of nodes). Modify T2 so that, for every node position, the value stored at that node in T2 equals the sum of all node values in the corresponding subtree of T1 (including the root of that subtree). Implement transform(TreeNode t1, TreeNode t 2) to perform this in O(n) time, and state your space complexity. Describe the traversal order you use and how you map positions between the two trees. For testing, also implement buildCompleteTree(int[] levelOrder) that constructs a complete binary tree from a level-order array representation.

Quick Answer: The question evaluates proficiency in binary tree algorithms, subtree aggregation, traversal techniques, array-to-tree construction, and analysis of time and space complexity.

Related Interview Questions

  • Implement Document Predicate APIs - Snowflake (medium)
  • Find Shortest Wiki Click Path - Snowflake (medium)
  • Schedule prerequisite classes with retakes - Snowflake (easy)
  • Solve three coding rounds - Snowflake (medium)
  • Minimize coins with overpay and change - Snowflake (hard)
Snowflake logo
Snowflake
Jul 26, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
3
0

You are given the roots of two complete binary trees T1 and T2 that have identical structure (same shape and number of nodes). Modify T2 so that, for every node position, the value stored at that node in T2 equals the sum of all node values in the corresponding subtree of T1 (including the root of that subtree). Implement transform(TreeNode t1, TreeNode t 2) to perform this in O(n) time, and state your space complexity. Describe the traversal order you use and how you map positions between the two trees. For testing, also implement buildCompleteTree(int[] levelOrder) that constructs a complete binary tree from a level-order array representation.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Snowflake•More Software Engineer•Snowflake Software Engineer•Snowflake Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • Careers
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL 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.