FastPrepGroup Loans by Top-Level Parent Company
Problems/Group Loans by Top-Level Parent Company

Group Loans by Top-Level Parent Company

Affirm logoAffirm● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: An Affirm report names this task: follow each company's chain of parents and group loan amounts by the top-level parent. The report does not give a full input and output format. So we chose these rules: companies are numbered by index. Every parent must be -1 or an earlier ancestor, with no cycles. Each loan is counted once. The answer is a list of [root, total] rows, sorted by root index from smallest to largest.

You are given a list of companies and a list of loans. Companies are numbered by their index. parents[i] is the parent company of company i. A company with no parent is a root company.

Loan j goes to company loanCompanies[j] and has amount amounts[j]. For each loan, follow the borrowing company's parent chain up to its root company, and add the loan's amount to that root's total.

Return one [rootIndex,totalAmount] row for each root that receives at least one loan. Sort the rows by root index, smallest first.

Function

groupLoans(parents: int[], loanCompanies: int[], amounts: long[]) → long[][]

Examples

Example 1

parents = [-1,0,-1,2]loanCompanies = [1,3,0]amounts = [5,7,2]return = [[0,7],[2,7]]

The loans to companies one and zero both roll up to root zero, for a total of seven. The loan to company three rolls up through company two, which is a root, so root two also totals seven.

Example 2

parents = [-1]loanCompanies = [0,0]amounts = [4,6]return = [[0,10]]

Both loans go to company zero, which is a root. Their amounts add up, so root zero totals ten.

Constraints

  • 1 <= parents.length <= 100000
  • parents[i] == -1 (company i has no parent) or 0 <= parents[i] < i.
  • loanCompanies and amounts have the same length.
  • Amounts are nonnegative, and every total fits in a signed 64-bit integer.

More Affirm interview questions

  • Redeemable Promotion OffersPHONE SCREEN · Seen Dec 2026
  • Propagating Fraud DetectorPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Cross-Day User Trust ScoresPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Count Distinct Underwriting PII ValuesPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • High-Card Pot GamePHONE SCREEN · Seen Sep 2026
  • Assign Sequential Loan IdentifiersPHONE SCREEN · Seen Sep 2026
  • Normalize Loan Merchants to Root BusinessesPHONE SCREEN · Seen Sep 2026
  • Group Transactions by HourONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Predicate Expression Tree EvaluatorMongoDB · PHONE SCREENMongoDB interview questions
  • Lowest Common Manager for Employee GroupsAmazon · PHONE SCREEN
  • Lowest Common Manager for Employee GroupsGoogle · PHONE SCREENGoogle interview questions
  • Collatz Conjecture with Shared MemoizationBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • House Robber IIIOkta · PHONE SCREENOkta interview questions
  • House Robber IIIGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
  • Tree Selection and VisibilityJane Street · PHONE SCREENJane Street interview questions
  • Account Roles With Parent-User InheritanceStripe · PHONE SCREENStripe interview questions
  • House Robber IIIVisa · PHONE SCREENVisa interview questions

Affirm interview experiences

  • Affirm SWE Virtual Onsite with AI Coding: 1 Experience
  • Affirm Staff SWE Virtual Onsite: 1 Experience
  • Affirm New Grad Frontend Interviews: 1 Experience
All Affirm interview questionsSee Affirm hiring insights
Saved
class Solution {
    public long[][] groupLoans(int[] parents, int[] loanCompanies, long[] amounts) {
      // Write your code here.
    }

}
Checking account…