Grokking Tree Coding Patterns for Interviews
Ask Author
Back to course home

0% completed

Vote For New Content
Bottom View Of the Binary Tree (medium)
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

Given the root of a binary tree, return an array that contains the nodes visible when looking at the tree from the bottom.

The bottom view is formed by collecting the nodes that would be visible if you were to stand directly beneath the tree and look up. If multiple nodes are aligned vertically, only the node at the deepest level should be included in the view.

Examples

Example 1

  • Input: root = [1, 2, 3]
  • Expected Output: [2, 1, 3]
Image
  • Justification: From the bottom view, nodes 2, 1, and 3 are visible because they appear at the lowest vertical and horizontal positions.

Example 2

  • Input: root = [1, 2, 3, 4, null, 5, 6]
  • Expected Output: [4, 2, 5, 3, 6]
Image
  • Justification: Nodes 4, 2, 5, 3, and 6 form the bottom view when observed from below. Each node is at its lowest level compared to any nodes that share the same vertical position.

Example 3

  • Input: root = [10, 7, 4, null, 9, 6, 11]
  • Expected Output: [7, 6, 4, 11]
Image
  • Justification: In this case, 7, 6, 4, and 11 are the nodes visible from the bottom as they are the deepest nodes at their respective vertical positions.

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible