Employee Salary Report by Group
Updated
Problem statement
You are building a small salary report. Employee i is employees[i] = [department, city, title] and earns salaries[i].
First apply the filters. Each filters[j] = [field, value] keeps only employees whose field equals value exactly (case matters). An employee stays in the report only if they pass every filter. With no filters, everyone stays.
Then put the remaining employees into groups by the field named groupBy, and compute aggregate over each group's salaries: "sum" (total), "min" (smallest), "max" (largest), "count" (number of employees) or "avg" (the total divided by the count, rounded down to a whole number).
Return one string "group:value" per group, for example "Eng:371", sorted by group name in character-code order (so uppercase letters come before lowercase ones). If no employee passes the filters, return an empty list.
Function
salaryReport(employees: String[][], salaries: int[], groupBy: String, aggregate: String, filters: String[][]) → String[]Examples
Example 1
employees = [["Sales","Austin","Rep"],["Eng","Austin","Dev"],["Sales","Boston","Lead"],["Eng","Boston","Dev"],["Eng","Austin","Lead"]]salaries = [50,120,90,100,151]groupBy = "department"aggregate = "sum"filters = []return = ["Eng:371","Sales:140"]No filters, so everyone counts. Eng has 120 + 100 + 151 = 371 and Sales has 50 + 90 = 140. Eng comes before Sales.
Example 2
employees = [["Sales","Austin","Rep"],["Eng","Austin","Dev"],["Sales","Boston","Lead"],["Eng","Boston","Dev"],["Eng","Austin","Lead"]]salaries = [50,120,90,100,151]groupBy = "city"aggregate = "avg"filters = [["department","Eng"]]return = ["Austin:135","Boston:100"]Only the three Eng employees pass the filter. Austin has 120 and 151, an average of 135.5, rounded down to 135. Boston has only 100.
Example 3
employees = [["Sales","Austin","Rep"],["Eng","Austin","Dev"],["Sales","Boston","Lead"],["Eng","Boston","Dev"],["Eng","Austin","Lead"]]salaries = [50,120,90,100,151]groupBy = "title"aggregate = "min"filters = [["city","Boston"]]return = ["Dev:100","Lead:90"]Only the two Boston employees pass. The Dev group has 100 and the Lead group has 90, so each group's minimum is that one salary.
Constraints
1 <= employees.length <= 1000andsalaries.length == employees.lengthemployees[i].length == 3, and every department, city, title and filter value has 1 to 10 English letters.1 <= salaries[i] <= 10^6groupByand everyfilters[j][0]is one of"department","city"or"title".aggregateis one of"sum","min","max","avg"or"count".0 <= filters.length <= 3andfilters[j].length == 2
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
- Group AnagramsWorkday · PHONE SCREEN
- Group AnagramsEPAM · PHONE SCREENEPAM interview questions
- Find Duplicate File GroupsAnthropic · PHONE SCREENAnthropic interview questions
- Insert an Employee into an Organization HierarchyWaymo · PHONE SCREENWaymo interview questions
- Group AnagramsMotive · PHONE SCREEN · ONSITE INTERVIEWMotive interview questions
- Stable Top K Frequent WordsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Group AnagramsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Find Duplicate Image FilesAbnormal Security · PHONE SCREEN
- Credit Card Command ProcessorChime · PHONE SCREEN
- Shared Courses for Every Pair of StudentsCrunchyroll · PHONE SCREENCrunchyroll interview questions