FastPrepWebsite Pair with the Most Common Visitors

Website Pair with the Most Common Visitors

ZipRecruiter logoZipRecruiter● MediumNEW GRADPHONE SCREEN
Learn

Problem statement

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.

More ZipRecruiter problems

See ZipRecruiter hiring insights
public String[] mostCommonVisitorPair(String[][] visits) {
    // Write your code here.
}
visits[["u1","a"],["u1","b"],["u2","a"],["u2","b"],["u3","c"]]
expected["a", "b"]
Checking account…