FastPrepCount Parent Nodes With a Target Sum
Problems/Count Parent Nodes With a Target Sum

Count Parent Nodes With a Target Sum

Adobe logoAdobe● EasyNEW GRADOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source omits the null-token convention, callable signature, numeric bounds, and examples. This practice version uses an explicit # marker and a 2,000-node bound. The judged core task matches the visible source at about 94%.

A binary tree is serialized in preorder as one comma-separated string preorder. Each non-null node is written as its signed integer value, and each missing child is written as #.

A parent node qualifies only when it has both a left child and a right child. Count the qualifying parent nodes whose own value plus the values of their two direct children equals target.

Return the total number of qualifying parent nodes.

Function

countTargetParents(preorder: String, target: long) → int

Examples

Example 1

preorder = "5,3,#,#,2,#,#"target = 10return = 1

The root has direct children 3 and 2, and 5 + 3 + 2 = 10. The leaves are not parent nodes.

Example 2

preorder = "1,2,4,#,#,5,#,#,3,#,6,#,#"target = 11return = 1

Node 2 has children 4 and 5, so it qualifies because 2 + 4 + 5 = 11. Node 3 has only one child and does not qualify.

Constraints

  • The serialization describes one valid, non-empty binary tree.
  • 1 <= number of non-null nodes <= 2000
  • -10^9 <= node value <= 10^9
  • -3 * 10^9 <= target <= 3 * 10^9
  • Tokens are separated by commas and may contain surrounding spaces.

Source note: Screenshot of the public LeetCode discussion text describing the reported Adobe OA task. The practice version adds the details stated in the source note.

More Adobe problems

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
All Adobe interview questionsSee Adobe hiring insights
Saved
class Solution {
    public int countTargetParents(String preorder, long target) {
        // Write your solution here
    }
}
Checking account…