← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Given the root of a binary tree, return the sum of the values of its perimeter nodes. The perimeter is defined as the union of three groups of nodes, listed in anti-clockwise order: (1) the left boundary — the path from the root to the left-most leaf (always taking the left child if it exists, otherwise the right child); (2) all leaf nodes that are not already part of the left or right boundary, collected left-to-right; (3) the right boundary — the path from the right-most leaf up to the root (always taking the right child if it exists, otherwise the left child). Nodes that appear in more than one group (e.g., the root or a leaf that is also a boundary node) must be counted only once in the final sum.