Top-K URLs Overall and in the Last 24 Hours
Updated
Problem statement
You are given access-log records in parallel arrays. Record i contains URL urls[i] and Unix-second timestamp timestamps[i].
Return two ranked URL lists:
- the top
kURLs across all records; - the top
kURLs whose timestamps are in the inclusive interval[queryTime - 86400, queryTime].
Rank a URL with more accesses first. Break equal-frequency ties by lexicographically smaller URL. If a group contains fewer than k distinct URLs, return all of them. The result is a two-row string matrix in overall-then-recent order.
Function
topKUrls(urls: String[], timestamps: long[], queryTime: long, k: int) → String[][]Examples
Example 1
urls = ["old","old","old","new","new","edge"]timestamps = [1,2,3,200000,199999,113600]queryTime = 200000k = 2return = [["old","new"],["new","edge"]]Overall, old appears three times and new twice. Only new and edge fall in the inclusive recent window.
Example 2
urls = ["b","a","c"]timestamps = [10,10,10]queryTime = 10k = 5return = [["a","b","c"],["a","b","c"]]All frequencies tie, so lexicographic order decides; fewer than k distinct URLs are returned.
Constraints
1 <= urls.length = timestamps.length <= 2 * 10^51 <= k <= 10^5- Each URL is a non-empty lowercase path of length at most
100. 0 <= timestamps[i] <= queryTime <= 10^12
More Oracle Phone Screen questions
- Remove Parentheses from a Plus-Minus ExpressionPHONE SCREEN · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · Seen Oct 2026
- Shortest Window by Distinct-Value SumPHONE SCREEN · Seen Oct 2026
- Detect a Cycle in a Directed GraphPHONE SCREEN · Seen Oct 2026
- Time-Based Key-Value StorePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Remove Adjacent Duplicates in String IIPHONE SCREEN · Seen Oct 2026
- Sum Root-to-Leaf Binary NumbersPHONE SCREEN · Seen Oct 2026
- Longest All-Present Attendance StreakPHONE SCREEN · Seen Oct 2026
- Next PermutationPHONE SCREEN · Seen Sep 2026
- Valid ParenthesesPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Travelers per Consecutive City TripletUber · ONSITE INTERVIEWUber interview questions
- Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
- Group AnagramsAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
- Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Filter, Sort, and Deduplicate Scheduled TasksRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Count Zero Request ServersSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Longest Consecutive SequenceJP Morgan Chase · PHONE SCREENJP Morgan Chase interview questions
- Top K Frequent Elements with a Recency TiebreakSwiggy · PHONE SCREEN
- Pins Violation Log QueriesPinterest · PHONE SCREENPinterest interview questions
- Group AnagramsWorkday · PHONE SCREEN