Last Updated: 7 Oct, 2025

Festival Peak Stalls

Easy
Asked in company
Google inc

Problem statement

A city festival is hosting N food stalls along its main street. Each stall i has a scheduled operation period, defined by a start time and an end time. A stall is considered "operating" at any given moment t if starttime <= t < endtime.


Your task is to find the maximum number of food stalls that are operating simultaneously at any point during the festival.


Input Format:
The first line of input contains an integer N, the number of nodes.

The second line contains N space-separated integers, representing the parent of each node from 0 to N-1.


Output Format:
For each depth from 0 to the maximum depth of the tree, print a line in the format: Depth D : C

D is the depth, and C is the count of nodes at that depth.

The output must be ordered by depth, starting from 0.


Note:
The interval is inclusive of the start time and exclusive of the end time ([start, end)). This means a stall that ends at hour 5 and another that starts at hour 5 are not operating simultaneously.