Platform Referral Rewards
Updated
Problem statement
Each string in records has the form worker referrer bonus. referrer is another worker name or None. Records may arrive in any order.
For every worker with a referrer and bonus b, the direct referrer earns b, that referrer's referrer earns b+1, the next ancestor earns b+2, and so on to the root. Bonuses may be positive, zero, or negative. Workers do not earn their own listed bonus.
Return all worker names sorted by decreasing total reward. Break equal-reward ties lexicographically.
Function
platformReferralRanking(records: String[]) → String[]Examples
Example 1
records = ["A None 0","B C 5","C None 0","D A 10","E D -3"]return = ["A","C","B","E","D"]Rewards are A=8, C=5, B=0, E=0, and D=-3.
Example 2
records = ["B A 2","C B 2","A None 0"]return = ["A","B","C"]A earns 2 from B and 3 from C, while B earns 2 from C.
Example 3
records = ["Z None 0","A None 0"]return = ["A","Z"]Both rewards are zero, so lexicographic order decides the result.
Constraints
1 <= records.length <= 200000.- Every record contains a unique worker name, a referrer name or
None, and a signed 32-bit bonus. - Worker names are nonempty ASCII alphanumeric strings of length at most
40. - The referral relation is acyclic and every named referrer belongs to the same forest.
- Every total reward fits in a signed 64-bit integer.
More Scale AI Online Assessment questions
- Part 2: Batch Access ReviewOA · Seen Nov 2026
- Part 1: The Narrowest KeyOA · Seen Nov 2026
- Build Sessions from Unordered Events (Part 1)OA · Seen Oct 2026
- Match Billing Charges to User Sessions (Part 2)OA · Seen Oct 2026
- Four-Player Trick-Taking Card Game SimulationOA · PHONE SCREEN · Seen Aug 2026
- Free Windows Between Busy IntervalsOA · PHONE SCREEN · Seen Apr 2026
- Compare Labeling Worker AnnotationsOA · Seen Mar 2025
- Count Stable Server SubsegmentsOA · Seen Nov 2024
- Distinct OR Values of Increasing SubsequencesOA · Seen Nov 2024
- Running Through Walls with Limited EnergyOA · Seen Sep 2024
Similar questions at other companies
- Maximum Reservoir PowerWells Fargo · OAWells Fargo interview questions
- Shipping Starts and Terminal DestinationsIntuit · OAIntuit interview questions
- Minimum Leaf Path Sum over All RootsInfosys · OAInfosys interview questions
- Divide Tree NodesGoogle · OA · ONSITE INTERVIEWGoogle interview questions
- Minimum Satellite Data Transfer IterationsHSBC · OAHSBC interview questions
- Maximum Strength of Every NeuronMicrosoft · OAMicrosoft interview questions
- Tree Node With Maximum BeautyC3.ai · OAC3.ai interview questions
- Top-Down Employee Reporting ForestOkta · ONSITE INTERVIEWOkta interview questions
- Aggregate Machine TopologyOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Distance Sums to Special Nodes in a Weighted TreeNutanix · ONSITE INTERVIEWNutanix interview questions