Find Mismatched Totals in a Binary Account Rollup Tree

Last updated: November 29, 2026

Quick Overview

A rollup tree stores a dollar amount at every node: leaves are individual account balances and each internal node should equal the sum of the leaves beneath it. Return the names of the internal nodes whose stored amount is wrong.

SoFi
Coding & Algorithms
Software Engineer
SoFi
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


A rollup tree stores a dollar amount at every node: leaves are individual account balances and each internal node should equal the sum of the leaves beneath it. Return the names of the internal nodes whose stored amount is wrong.

Finance and reporting systems at SoFi roll account balances up into product and business-line totals, and a silently wrong subtotal is a real audit problem. The interviewer checks post-order recursion and, importantly, that you validate against recomputed child totals rather than trusting stored subtotals that may themselves be wrong.

What the Interviewer Expects
  • Uses post-order traversal so children are computed before parents
  • Recomputes totals from leaves instead of trusting a child's stored amount
  • Distinguishes leaves from internal nodes with one child
  • Collects all mismatches rather than stopping at the first
  • Mentions recursion depth limits for very deep trees
Key Topics to Cover
binary trees
post-order traversal
recursion
data validation
financial reporting
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Should a parent be flagged if its only error comes from a wrong child subtotal? Defend your choice.
  • How would you convert this to an iterative traversal?
  • How would you report the size of each discrepancy?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Each node has name, amount (integer cents) and up to two children. A node with no children is a leaf whose amount is the source of truth. An internal node is correct when its amount equals the sum...

High-Level Design

A helper returns the true leaf total of a subtree. For a leaf it returns its own amount. For an internal node it sums the true totals of its children, compares to the stored amount, records a mismatch...


Submit Your Answer
Markdown supported

Related Questions