Top-K URLs Overall and in the Last 24 Hours
Reported by candidates from Oracle's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The whole Oracle question from September 2026 comes down to one data structure: a heap, or a sort that does the same job, sitting on top of a frequency map. You get access logs as parallel arrays and need two ranked lists, top k overall and top k in the 24 hours ending at queryTime. Ties go to the lexicographically smaller URL. Nothing here is exotic, but the tie-break and the inclusive window bite people who rush. If you blank mid-assessment, StealthCoder runs invisibly on your desktop and gives you a working solution in real time.
The problem
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 k URLs across all records; the top k URLs 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 = 200000 k = 2 return = [["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 = 10 k = 5 return = [["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^5 1 <= k <= 10^5 Each URL is a non-empty lowercase path of length at most 100. 0 <= timestamps[i] <= queryTime <= 10^12
Reported by candidates. Source: FastPrep
Pattern and pitfall
Do two passes with the same helper. Pass one counts every URL in a hash map. Pass two counts only records where timestamps[i] >= queryTime - 86400 and timestamps[i] <= queryTime. Both boundaries are inclusive, and Example 1 tests it with the record at 113600, which sits exactly on the lower edge. Then rank each map. Sorting the distinct entries by count descending, then URL ascending, is simplest and fine at 2 * 10^5 records. A size-k min-heap with a comparator that matches the tie-break is the tighter option. The classic pitfall is a heap comparator that gets the tie direction backwards, so the wrong URL gets evicted. Also remember that fewer than k distinct URLs means returning all of them, not padding. If the comparator logic tangles under pressure, StealthCoder is the hedge during the live OA.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Top-K URLs Overall and in the Last 24 Hours cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Oracle's OA.
Oracle reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Top-K URLs Overall and in the Last 24 Hours FAQ
What's the trick in the Oracle top-K URLs problem?+
Build a frequency hash map, then rank entries by count descending and URL ascending. Do it twice, once on all records and once on records inside the window. A custom comparator handles the tie-break. Everything else is bookkeeping.
Should I use a heap or just sort?+
Either passes at 2 * 10^5 records. Sorting distinct URLs is shorter and harder to get wrong. A size-k heap gives O(n log k) and is worth it if you want to show the pattern. Pick the one you can write without bugs in one try.
Is the 24-hour window inclusive on both ends?+
Yes. A record counts if its timestamp is between queryTime - 86400 and queryTime, both included. Example 1 has a record at 113600, exactly on the lower boundary with queryTime 200000, so an off-by-one with strict less-than gets it wrong.
What if there are fewer than k distinct URLs?+
Return all of them, ranked by the same rules. Example 2 shows this with k = 5 and only three URLs. Don't pad with empty strings. The recent list can also be shorter than the overall list, or even empty.
How do I prepare for this in 48 hours?+
Write a top-K frequent elements solution with a custom comparator twice, once with sorting and once with a heap. Then add the timestamp filter. Test ties and the boundary timestamp by hand. Reported at Oracle in September 2026, it's a standard pattern with two small twists.