Count Value Occurrences in a Binary Tree

Asked at Apple · Coding Questions · Difficulty: Medium · Last asked Dec 10, 2025

You are given the root of a binary tree (not a BST, just a generic binary tree) and a target value x. Count how many nodes in the tree have node.val == x.

Loading the problem…