PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCareers
|Home/Coding & Algorithms/Snowflake

Set second tree values by subtree sums

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's competence in binary tree data structures and algorithmic efficiency, focusing on tree traversal techniques, subtree aggregation, and handling robustness aspects such as empty trees and integer overflow.

  • Medium
  • Snowflake
  • Coding & Algorithms
  • Software Engineer

Set second tree values by subtree sums

Company: Snowflake

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

Given the roots of two complete binary trees T1 and T2 that have identical structure and the same number of nodes, replace each value in T2 with the sum of all node values in the corresponding subtree of T1 (including the matching root of that subtree). Implement: ( 1) a function that performs this transformation in O(n) time and O(h) extra space, where n is the number of nodes and h is tree height; ( 2) helpers to build a complete binary tree from a level-order array (use null for missing children) and to serialize a tree back to an array for testing. State assumptions and handle edge cases like empty trees, negative values, and integer overflow.

Quick Answer: This question evaluates a candidate's competence in binary tree data structures and algorithmic efficiency, focusing on tree traversal techniques, subtree aggregation, and handling robustness aspects such as empty trees and integer overflow.

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
Sep 6, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
4
0

Given the roots of two complete binary trees T1 and T2 that have identical structure and the same number of nodes, replace each value in T2 with the sum of all node values in the corresponding subtree of T1 (including the matching root of that subtree). Implement: (

  1. a function that performs this transformation in O(n) time and O(h) extra space, where n is the number of nodes and h is tree height; (
  2. helpers to build a complete binary tree from a level-order array (use null for missing children) and to serialize a tree back to an array for testing. State assumptions and handle edge cases like empty trees, negative values, and integer overflow.

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.