FastPrepTeam Cost Under a Manager
Problems/Team Cost Under a Manager

Team Cost Under a Manager

Rippling logoRippling● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: We built this from a short post by an SDE-2 candidate, posted July 3, 2022. For Rippling it lists one coding round, built on a public exercise where you total a value over an employee and everyone below them in the org chart. A follow-up came after the main task, and its content is unknown.

The post does not say what was changed, and gives no input format, limits or examples. We left the follow-up out. Here, the org chart is a flat list of ids, each with a manager id or -1 for a top-level person. A manager may come later in the list than their reports, and there can be several top-level people. The value is a whole-number monthly cost. A team total counts the person asked about plus all direct and indirect reports. Several ids are asked at once, answered in the order asked, and an id may be asked more than once. Totals can pass the 32-bit range. The limits and examples are our own.

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

A company keeps its org chart as a flat list. Person i has the id ids[i], a monthly cost costs[i], and a manager whose id is managerIds[i]. A top-level person has no manager, which is written as -1. There can be more than one top-level person, and a manager may appear later in the list than the people who report to them.

The team of a person is that person plus everyone below them: their direct reports, the reports of those reports, and so on.

For each id in queries, return the total monthly cost of that person's team. Return the answers in the same order as queries.

Function

teamCosts(ids: int[], managerIds: int[], costs: int[], queries: int[]) → long[]

Examples

Example 1

ids = [4,7,3,9,12]managerIds = [3,-1,7,7,3]costs = [5,50,20,30,8]queries = [3,7,12]return = [33,113,8]

Person 7 is the only top-level person. People 3 and 9 report to 7, and people 4 and 12 report to 3. Person 4 is listed before their manager 3. The team of 3 is 3, 4 and 12: 20 + 5 + 8 = 33. The team of 7 is everyone: 50 + 20 + 30 + 5 + 8 = 113. Person 12 has no reports, so the team is just 12: 8.

Example 2

ids = [1,2,3]managerIds = [-1,-1,2]costs = [10,0,6]queries = [2,1,2]return = [6,10,6]

There are two top-level people, 1 and 2. Person 3 reports to 2. The team of 2 costs 0 + 6 = 6, and the team of 1 is just 1, costing 10. The same id can be asked twice.

Example 3

ids = [30,20,10]managerIds = [20,10,-1]costs = [10000000,10000000,10000000]queries = [10,20]return = [30000000,20000000]

The list goes from the bottom of the chain to the top: 30 reports to 20, and 20 reports to 10. The team of 10 is all three people: 3 × 10^7 = 30000000. The team of 20 is 20 and 30: 20000000.

Constraints

  • 1 <= ids.length <= 2000, and managerIds and costs have the same length as ids
  • 1 <= ids[i] <= 10^5, and all ids are different.
  • Each managerIds[i] is -1 or the id of another person in ids, and going up from any person through their managers always ends at a top-level person (there are no loops).
  • 0 <= costs[i] <= 10^7
  • 1 <= queries.length <= 200, and every query is one of the ids in ids.

More Rippling Phone Screen questions

  • Filter, Sort, and Deduplicate Scheduled TasksPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Stateful Log Transform and SearchPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Dependency-Aware Task SchedulerPHONE SCREEN · Seen Nov 2026
  • Delivery Cost Tracker with Effective-Dated RatesPHONE SCREEN · Seen Nov 2026
  • Camel CardsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Best and Worst Camel Card CompletionsPHONE SCREEN · Seen Nov 2026
  • Corporate Card Expense RulesOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • In-Memory Priority Task SchedulerPHONE SCREEN · Seen Oct 2026
  • Limit an Organization Tree's HeightPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Median Across N Sorted ArraysPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Transform and Prune a Mode-Valued Binary TreeGoogle · PHONE SCREENGoogle interview questions
  • Top View of a Binary TreeInMobi · ONSITE INTERVIEWInMobi interview questions
  • N-ary Index-Path Encoder and DecoderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Account Roles With Parent-User InheritanceStripe · PHONE SCREENStripe interview questions
  • Find All Paths for a Name in a File SystemThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
  • Validate a BST with a Custom ComparisonApple · PHONE SCREENApple interview questions
  • Tree Height After Child PromotionSnowflake · PHONE SCREENSnowflake interview questions
  • Binary Tree Spiral Level OrderAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Check a Complete Binary TreeGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
  • Route Graph Reachability with a Broken LinkFigma · PHONE SCREENFigma interview questions

Interview reports that mention this question

  • Rippling SWE Loops and History: 23 Experiences (Part 10 of 12)

Rippling interview experiences

  • Rippling No-Level Older Reports: 31 Experiences (Part 6 of 6)
  • Rippling No-Level Onsite Loops: 24 Experiences (Part 5 of 6)
  • Rippling No-Level Screens and Loops: 18 Experiences (Part 4 of 6)
  • Rippling No-Level Coding Screens: 37 Experiences (Part 3 of 6)
  • Rippling No-Level Design, Screens: 30 Experiences (Part 2 of 6)
All Rippling interview questionsSee Rippling hiring insights
Saved
class Solution {
    public long[] teamCosts(int[] ids, int[] managerIds, int[] costs, int[] queries) {
        // Write your code here.
    }
}
Checking account…