call(back)
Algorithms & Data StructuresmediumSign in to star problems

Cross-Reference Logs to Flag Spam Numbers

You are given two logs:

callLog = [[caller, callee], ...]        // phone calls made
reports  = [[reporter, number], ...]     // users reporting a number as spam

A report is valid only if the reporter actually received a call from the number they reported (cross-referencing — this filters fake or mistaken reports). Flag every number with at least minReports distinct valid reporters. Return the flagged numbers sorted.

Hints

Hint 1

This is a hash join: build number -> set of people it called from the call log, then stream the reports and keep only those where the reporter appears in that set.

Hint 2

Count distinct valid reporters per number (a set per number — the same user reporting twice counts once), then threshold and sort.

Asked at