Website Pair with the Most Common Visitors
Reported by candidates from ZipRecruiter's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt on this ZipRecruiter OA, reported in November 2021, is counting visits instead of distinct visitors. Duplicate rows from one user quietly inflate your pair counts and you fail the second example. The task is a hash-table problem: group websites by user, then count co-occurring pairs. If you blank on the dedup step or the tie-break, StealthCoder runs invisibly on the screen as a safety net and gives you a working solution in real time. Know the shape before you start and you won't need it.
The problem
Each row of visits is [user, website]. A user may visit one website more than once, but contributes at most once to that website's visitor set. Among all unordered pairs of distinct websites, return the pair with the largest number of shared visitors. Sort the two names inside the result. Break ties by the lexicographically smallest pair. Return an empty array when fewer than two distinct websites appear. Function mostCommonVisitorPair(visits: String[][]) → String[] Examples Example 1 visits = [["u1","a"],["u1","b"],["u2","a"],["u2","b"],["u3","c"]] return = ["a","b"] Websites a and b share two visitors, more than any other pair. Example 2 visits = [["u1","a"],["u1","a"],["u1","b"],["u2","b"],["u2","c"]] return = ["a","b"] Repeated visits by one user do not inflate an intersection. Constraints 0 <= visits.length <= 50000 Every row contains exactly two nonempty strings.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is to flip the grouping. Build a map from user to a set of websites, so repeated visits collapse automatically. Then for each user, sort their sites, loop over every pair, and increment a counter keyed by the pair. Track the best count, and on ties keep the lexicographically smaller pair. The pitfall is skipping the set and counting raw rows, or forgetting that pairs must be unordered, so (a,b) and (b,a) must hit the same key. Sorting each user's sites fixes that. Watch the cost too. A user with many sites generates quadratic pairs, but with 50000 rows the total stays manageable. Return an empty array when fewer than two distinct websites exist. If the tie-break or dedup slips under pressure, StealthCoder is the hedge during the live OA, but this is about fifteen lines once you see it.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Website Pair with the Most Common Visitors 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. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass ZipRecruiter's OA.
ZipRecruiter reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Website Pair with the Most Common Visitors FAQ
What's the trick in the ZipRecruiter website pair problem?+
Dedupe first. Map each user to a set of websites so repeat visits don't count. Then enumerate sorted pairs per user and count them in a hash map. The pair with the highest count wins, with ties going to the lexicographically smaller pair.
How hard is this problem really?+
Medium at most. There's no fancy algorithm, just a hash map of sets and a pair counter. Most failures come from skipping the dedup, mishandling unordered pairs, or missing the tie-break and the empty-array edge case.
How do I handle ties correctly?+
Compare counts first. If a pair's count equals the current best, compare the two names lexicographically, first name then second, and keep the smaller. Since each pair is already sorted internally, a simple string comparison on the two elements works.
What edge cases should I test?+
Empty input, a single website across all rows, one user visiting the same site repeatedly, and users with only one distinct site. All of these should return an empty array or avoid inflated counts. Also test that (b,a) and (a,b) merge into one key.
How do I prepare for this in 48 hours?+
Write the user-to-set map and the pair counter from scratch twice. Practice the sorted-pair key and the tie-break comparison. That covers the whole problem. Then run the two provided examples by hand, especially the repeated-visit one.