FastPrepTree Height After Child Promotion
Problems/Tree Height After Child Promotion

Tree Height After Child Promotion

Snowflake logoSnowflake● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Deleting a node, moving its children up, and then finding the height is about 95% the same as the reported question. Height counts nodes, and the root is kept, as the task reference says. We supply the tree as a parent array, and we wrote the examples.

You are given a rooted tree in which a node may have any number of children and distinct non-root node IDs to delete. Deleting a node removes that node and attaches each of its current children directly to its parent. Apply every listed deletion and return the resulting tree height, measured as the number of nodes on the longest root-to-leaf path. The root remains, so a tree containing only the root has height 1.

For this exercise, nodes are labeled 1 through n, root 1, and parent[i - 2] is the parent of node i. Delete the node IDs in deleted. You may delete both an ancestor and one of its descendants. Keep attaching their children to the next parent as needed. The remaining parent-child relationships are the same regardless of deletion order.

Function

heightAfterPromotions(parent: int[], deleted: int[]) → int

Examples

Example 1

parent = [1,1,1,2,2]deleted = [2]return = 2

Deleting an internal node promotes both children.

Example 2

parent = [1,2,3]deleted = []return = 4

An unchanged four-node chain has height four.

Example 3

parent = [1,2,2]deleted = [3]return = 3

Deleting one leaf preserves the other deep path.

Constraints

  • 1 <= n = parent.length + 1 <= 10000.
  • The parent array describes one valid tree rooted at 1; parent IDs need not be smaller than child IDs.
  • deleted contains distinct existing IDs from 2 through n, possibly none or all non-root nodes.

More Snowflake Phone Screen questions

  • Minimum StackPHONE SCREEN · Seen Nov 2026
  • Design In-Memory File SystemPHONE SCREEN · Seen Nov 2026
  • Merge Two Binary TreesPHONE SCREEN · Seen Nov 2026
  • Connect Four from the Last MovePHONE SCREEN · Seen Nov 2026
  • Minimum Edits to a Perfect Binary TreePHONE SCREEN · Seen Nov 2026
  • Configurable Per-Client Token BucketsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Find Valid SET Card TriplesOA · PHONE SCREEN · Seen Nov 2026
  • Minimum Index Distance Between Person and CakeOA · PHONE SCREEN · Seen Nov 2026
  • Minimum N-ary Tree Depth DeletionsOA · PHONE SCREEN · Seen Nov 2026
  • Sum of Binary Tree Boundary NodesOA · PHONE SCREEN · Seen Nov 2026

Similar questions at other companies

  • Find All Paths for a Name in a File SystemThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
  • Binary Tree Spiral Level OrderAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Check a Complete Binary TreeGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
  • Tree DiameterQualcomm · PHONE SCREENQualcomm interview questions
  • Frog Position After T SecondsInMobi · PHONE SCREENInMobi interview questions
  • Distance Between Two Nodes in a Binary TreeBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Transform and Prune a Mode-Valued Binary TreeGoogle · PHONE SCREENGoogle interview questions
  • Time to Burn a Binary Tree From One NodeAdobe · PHONE SCREENAdobe interview questions
  • Team Cost Under a ManagerRippling · PHONE SCREENRippling interview questions
  • Symmetric Binary TreeDocuSign · PHONE SCREENDocuSign interview questions

Snowflake interview experiences

  • Snowflake AI Coding Interview, Experienced Hires: 3 Experiences
All Snowflake interview questionsSee Snowflake hiring insights
Saved
class Solution {
    public int heightAfterPromotions(int[] parent, int[] deleted) {
        // write your code here
    }
}
Checking account…