Remove Repeat Search Result URLs From an Unsorted Linked List
Last updated: November 29, 2026
Quick Overview
Search results arrive as an unsorted singly linked list of URLs. Remove later duplicates so each URL keeps only its first occurrence, preserving the original order.
0
0
0 solved
Search results arrive as an unsorted singly linked list of URLs. Remove later duplicates so each URL keeps only its first occurrence, preserving the original order.
Google uses this as an opener that branches into a space-time trade-off discussion. A hash set gives one pass; the follow-up asks for no extra memory, which forces the O(n^2) runner technique, and the interviewer wants you to compare both clearly.
What the Interviewer Expects
- One pass with a hash set of seen URLs
- Unlink duplicates while keeping a pointer to the last kept node
- Preserve the order of first occurrences
- Offer the O(1) space, O(n^2) time runner variant
- Discuss normalizing URLs before comparing
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Do it without any extra data structure.
- Keep the last occurrence of each URL instead of the first.
- URLs differ by tracking parameters. How would you canonicalize them?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: head of an unsorted singly linked list of strings.
- Output: same list with later duplicates unlinked, first occurrences in original order.
- Target O(n) time; also discuss O(1) space....
High-Level Design
Walk the list with prev, the last node we kept, and a set of URLs already kept. For each next node: if its URL is in the set, unlink it from prev; otherwise add it to the set and advance prev. T...