Monthly Archives: October 2023

C# || How To Find Largest Value In Each Binary Tree Row Using C#

The following is a module with functions which demonstrates how to find the largest value in each binary tree row using C#.


1. Largest Values – Problem Statement

Given the root of a binary tree, return an array of the largest value in each row of the tree (0-indexed).

Example 1:


Input: root = [1,3,2,5,3,null,9]
Output: [1,3,9]

Example 2:


Input: root = [1,2,3]
Output: [1,3]


2. Largest Values – Solution

The following is a solution which demonstrates how to find the largest value in each binary tree row.

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

Once compiled, you should get this as your output for the example cases:


[1,3,9]
[1,3]