FastPrepTotal Balance of an Account and Its Sub-Accounts
Problems/Total Balance of an Account and Its Sub-Accounts

Total Balance of an Account and Its Sub-Accounts

Capital One logoCapital One● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A February 2015 Capital One software engineer report, from a process with behavioral, technical and case interviews, describes accounts arranged in a hierarchy and wants the total for one chosen account, counting everything under it.

No format is given. Here accounts are rows holding an id, a parent id and a balance, the topmost account has parent -1, the query is the id of one account, and the answer counts that account and everything below it. Balances are whole numbers of at most 10^6, with up to 1000 accounts. These are our choices.

Our version is about 75% the same as the reported question.

A bank keeps its accounts in a hierarchy. Each row of accounts is [id, parentId, balance]: an account, the account it sits directly under, and the money it holds. The one top-level account has parentId = -1. Rows come in any order.

target is the id of one account. Return the total balance of that account together with all of its sub-accounts, at every depth.

Function

accountTotal(accounts: int[][], target: int) → int

Examples

Example 1

accounts = [[8,7,10],[7,100,40],[100,-1,500],[20,64,3],[31,100,25],[64,31,5]]target = 100return = 583

Account 100 is the top of the hierarchy, so its total includes every account: 500 + 40 + 25 + 10 + 5 + 3 = 583; account 20 sits three levels down, under 64, under 31.

Example 2

accounts = [[8,7,10],[7,100,40],[100,-1,500],[20,64,3],[31,100,25],[64,31,5]]target = 7return = 50

Account 7 has one sub-account, 8. The total is 40 + 10 = 50; the sibling branch under 31 is not included.

Example 3

accounts = [[9,-1,0]]target = 9return = 0

The only account has no sub-accounts, so the total is its own balance, 0.

Constraints

  • 1 <= accounts.length <= 1000
  • 0 <= id, balance <= 10^6, and all ids are different.
  • Exactly one account has parentId = -1, every other parent id is the id of an account, and target is an id in accounts.

More Capital One Onsite Interview questions

  • Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
  • Sort ColorsONSITE INTERVIEW · Seen Oct 2026
  • Virtual Card Transaction ValidatorONSITE INTERVIEW · Seen Oct 2026
  • Banking System with Top ActivityONSITE INTERVIEW · Seen Sep 2026
  • Transaction Event StoreONSITE INTERVIEW · Seen Jul 2026
  • Shortest Path in an Unweighted GraphONSITE INTERVIEW · Seen Jul 2026
  • Duplicate Transactions Within 60 SecondsONSITE INTERVIEW · Seen May 2026
  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
  • Cashback TrackerONSITE INTERVIEW · Seen Nov 2025
  • Reverse a StringOA · ONSITE INTERVIEW · Seen Oct 2025

Similar questions at other companies

  • N-ary Index-Path Encoder and DecoderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Delete Nodes and Return Forest RootsGoogle · ONSITE INTERVIEWGoogle interview questions
  • JSON Path Lookup with Implicit Array WildcardsMongoDB · ONSITE INTERVIEWMongoDB interview questions
  • Merge N-Ary Trees by KeyLinkedIn · PHONE SCREEN · ONSITE INTERVIEWLinkedIn interview questions
  • Filesystem Hash TreeCursor · PHONE SCREEN · ONSITE INTERVIEWCursor interview questions
  • Render an Org Chart and Find Skip-Level PairsSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
  • Render a Comment HierarchyAmazon · ONSITE INTERVIEW
  • Topmost Accessible NodesFigma · PHONE SCREEN · ONSITE INTERVIEWFigma interview questions
  • Outline from Flat Parent RecordsRippling · ONSITE INTERVIEWRippling interview questions
  • Top View of a Binary TreeInMobi · ONSITE INTERVIEWInMobi interview questions

Capital One interview experiences

  • Capital One Experienced Engineer Power Day and OA: 6 Experiences
  • Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
  • Capital One TDP Agentic Round (AI Coding): 7 Experiences
  • Capital One SWE Power Day, Level Not Reported: 6 Experiences
  • Capital One TIP Intern OA and Power Day: 13 Experiences
  • Capital One TDP Agentic Power Day: 25 Experiences (Part 1 of 2)
All Capital One interview questionsSee Capital One hiring insights
Saved
class Solution {
    public int accountTotal(int[][] accounts, int target) {
        // Write your code here.
    }
}
Checking account…