Select the Top User Matches
Updated
Problem statement
You are given parallel arrays userIds and scores, where each score was computed in constant time against one selected user. Return the IDs of the n best matches.
Put higher scores first. If scores tie, put the smaller user ID first. n is much smaller than the number of candidates.
Function
topMatches(userIds: int[], scores: int[], n: int) → int[]Examples
Example 1
userIds = [10,20,30,40]scores = [5,9,9,2]n = 2return = [20,30]Users 20 and 30 tie for the highest score and are ordered by ID.
Example 2
userIds = [8,3,5]scores = [-1,4,2]n = 1return = [3]User 3 has the highest score.
Constraints
1 <= userIds.length == scores.length <= 1000000- User IDs are distinct signed 32-bit integers.
- Scores are signed 32-bit integers.
1 <= n <= userIds.length.
More Duolingo Phone Screen questions
- Group Timestamps into Consecutive-Day IntervalsPHONE SCREEN · Seen Nov 2026
- Return Every Matching DecryptionPHONE SCREEN · Seen Nov 2026
- Visit Desired Attractions Without Reusing a TrailPHONE SCREEN · Seen Oct 2026
- Correct an In-Place Array ReversalPHONE SCREEN · Seen Oct 2026
- Count Starts Reaching a Grid MaximumPHONE SCREEN · Seen Oct 2026
- Sum All Values in a Binary TreePHONE SCREEN · Seen Oct 2026
- User Resource Transition ProbabilitiesPHONE SCREEN · Seen Oct 2026
- Encrypt and Decrypt StringsPHONE SCREEN · Seen Apr 2026
- Validate a Mahjong Hand PartitionPHONE SCREEN · Seen Nov 2025
- Directional Tiles: Find a Valid Reconfiguration PathPHONE SCREEN · Seen Oct 2022
Similar questions at other companies
- Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Top K Frequent ElementsAmazon · OA · PHONE SCREEN
- Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
- Maximum Number of Events That Can Be AttendedByteDance · PHONE SCREENByteDance interview questions
- Meeting Rooms IIeBay · PHONE SCREENeBay interview questions
- Meeting Rooms IIQuince · PHONE SCREENQuince interview questions
- Kth Largest Element in an ArrayLinkedIn · PHONE SCREENLinkedIn interview questions
- Meeting Rooms IISecuronix · PHONE SCREEN
- Merge Multiple Sorted StreamsNVIDIA · PHONE SCREENNVIDIA interview questions
- Maximum Number of Events That Can Be AttendedSnowflake · PHONE SCREENSnowflake interview questions