Search⌘ K

DIY: All Nodes Distance K in Binary Tree

Explore how to solve the problem of finding all nodes at a given distance K from a target node in a binary tree. Learn to implement the distance_k function in Ruby, developing skills to traverse trees and apply algorithms useful for interview preparation.

Problem statement

We are given a binary tree (with a root node root), a target node, and an integer value, kk.

Return a list of the values of all nodes that are kk ...