Rubrik 2022-August | Tree Flattening & Segment Trees | Hard-CP

Rubrik · Question · Posted Jun 2026

Question 1: Subtree Sum Queries Problem Statement You are given a tree consisting of N nodes rooted at node 1. Each node has an integer value assigned to it. You need to process Q queries of two types: 1 X V : Update the value of node X to V. 2 X : Calculate and print the total sum of values in the subtree of node X. Input Format The first line contains N and Q. The second line contains ...

The full answer & interview discussion are available to premium members.

Log in Create a free account