Relative Score Graph Components
Updated
Problem statement
Each string in comparisons has the form A B d and means score(A) = (1+d) × score(B). The comparisons are consistent and may form several disconnected components.
If anchors is nonempty, it contains exactly one name score record per component. Return a one-element array containing the globally highest-scoring response.
If anchors is empty, return the highest-scoring response from every component, sorted lexicographically. Break score ties lexicographically.
Function
highestRelativeScores(comparisons: String[], anchors: String[]) → String[]Examples
Example 1
comparisons = ["A B 0.1","B E 0.2","C D -0.5","D E 1.0","F G 0.05"]anchors = ["E 1.0","F 1.05"]return = ["D"]In E's component, D has score 2.0, which is above every other anchored response.
Example 2
comparisons = ["A B 0.1","B D 0.2","E F -0.5"]anchors = []return = ["A","F"]A is highest in the first component and F in the second; names are sorted for the return value.
Example 3
comparisons = ["A B 0.0"]anchors = []return = ["A"]A and B tie, so the lexicographically smaller name wins.
Constraints
1 <= comparisons.length <= 200000.- Names are nonempty ASCII alphanumeric strings of length at most
40. -0.99 < d <= 1000, so every multiplicative factor is positive.- The graph is internally consistent.
anchorsis empty or contains exactly one positive finite score per component.
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
- Unit Conversion IIApple · PHONE SCREENApple interview questions
- Frog Position After T SecondsInMobi · PHONE SCREENInMobi interview questions
- Count Pairs of Nodes That Cannot Reach Each OtherAdobe · PHONE SCREENAdobe interview questions
- Count Components With a Prime Total ValueNutanix · ONSITE INTERVIEWNutanix interview questions
- Count Prime Values in SubtreesVisa · OAVisa interview questions
- Minimum Cleaning Robot RunsHSBC · OAHSBC interview questions
- Number of IslandsGoldman Sachs · OA · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
- Maximum Data Transfer TimeMicrosoft · OAMicrosoft interview questions
- Validate a DFS Traversal OrderRippling · OARippling interview questions
- Can Sort Permutation in Given MovesAmazon · OA