AO
Back

Pin Policy Violation Log: Unique Pins by Policy and Time Range

Also reported as Pins Violation Log · Violation Log Analyzer · Log Violation Analysis

CodingOnsiteLast reported September 2026Medium Frequency

Problem Overview

The round: six Pinterest reports, phone screens and onsite coding rounds, posted between February and September 2026. You get a log of policy violations: each record says which post (a pin) broke which policy, and when. One phone-screen report lists the version it got as five small questions over a log that is already sorted by timestamp, and says the candidate had to run test cases live. Another phone-screen report gives three questions of the same kind over (pinId, policy, date) records and notes that pin ids repeat, so counts must dedupe. An onsite report with two parts says the first was a hash-map pass and the second needed binary search; it does not say which of the five questions below those were. Five graded parts, in the order the five-question report lists them.

Every part takes the whole log as records: a list of [post_id, policy, timestamp] records sorted by timestamp (non-decreasing). The same post can appear many times (reported: pin ids repeat), and the exact same record can appear twice (ours: then Part 5 counts it twice as violations). A timestamp is an integer or a "YYYY-MM-DD" date string, one kind per log (ours: one report uses date strings but gives no format); both sort correctly, so one solution handles both.

Part 1 — unique posts for a policy

def count_unique_posts_by_policy(records: list, policy: str) -> int: ...
  • The number of distinct posts with at least one record for policy. An unknown policy gives 0.

Part 2 — policies a post violated

def policies_for_post(records: list, post_id) -> set: ...
  • The distinct policies post_id violated, in any order (the tests sort them). An unknown post gives an empty set.

Part 3 — unique posts at one timestamp

def count_unique_posts_at(records: list, timestamp) -> int: ...
  • The number of distinct posts with a record at exactly timestamp.
  • The log is sorted, so a binary search you write can find the matching block instead of scanning the whole log (our suggested approach; not graded).

Part 4 — unique posts in a time range

def count_unique_posts_in_range(records: list, start, end) -> int: ...
  • The number of distinct posts with a record whose timestamp is in [start, end], both ends included. start > end gives 0.

Part 5 — violations by policy in a time range

def count_violations_by_policy_in_range(records: list, start, end, unique_posts: bool = False) -> dict: ...
  • For records with a timestamp in [start, end], a dict from policy to a count. Only policies with at least one record in the range appear.
  • unique_posts=False (the default) counts records: every violation counts once, duplicates included. unique_posts=True counts distinct posts per policy instead, which is the third question in the other phone-screen report. The two reports name this part differently, so ask which one is meant.

Example

log = [[1, "spam", 100], [2, "spam", 100], [1, "nudity", 105], [3, "spam", 110],
       [1, "spam", 110], [2, "hate", 120], [4, "nudity", 120], [2, "spam", 130]]

count_unique_posts_by_policy(log, "spam")            -> 3        (posts 1, 2, 3)
policies_for_post(log, 1)                            -> {"nudity", "spam"}
count_unique_posts_at(log, 110)                      -> 2        (posts 3 and 1)
count_unique_posts_in_range(log, 105, 120)           -> 4
count_violations_by_policy_in_range(log, 100, 120)   -> {"spam": 4, "nudity": 2, "hate": 1}
count_violations_by_policy_in_range(log, 100, 120, unique_posts=True)
                                                     -> {"spam": 3, "nudity": 2, "hate": 1}

Notes: the five questions, the record shape, the sorted log, the dedupe and a binary search somewhere in the question are from the reports. Using binary search for Parts 3 to 5, exact duplicate records and how they count, the "YYYY-MM-DD" format, the function names, passing the log to every function, inclusive range ends, the unique_posts switch, the empty results and every example and test are ours. One report mentions a simple follow-up without saying what it was. Speed is not graded here: the editor cannot time your code, so the tests check only the answers; say the cost of each part out loud instead.

Follow-up Arc

Interviewers escalate through these phases. The order varies, but most candidates see at least one from each bucket.
Trade-off discussion · 2
Trade-off discussion

Count the unique posts in a time range on the sorted log

Probes for: after the hash-map parts; one onsite report says its second part needed binary search, without saying which

Count violations by policy in a time range; one report asks for unique pins per policy in the range instead

What Reports Emphasize

What the reports say: six reports, phone screens and onsite coding rounds. One lists five small questions over a log sorted by timestamp and says tests ran live; that candidate finished three. Another says pin ids repeat and counts must dedupe. An onsite report with two parts says the second needed binary search, without saying which question that was. One phone screen with this question was failed and one was passed.

Common mistakes (ours, not reported): Counting records instead of distinct posts; scanning a sorted log instead of binary search; an off-by-one at the range ends.

Edge cases to test (ours): A duplicate record; a timestamp between records; a range that starts or ends on a record; an empty log.

Practice

Write your own against 13 test cases, or read the worked solution — approach, complexity, and code that runs.
Did this match your interview?

If you have had this round, tell us how close this page was. It is how we keep the pages accurate.

Prepping for Pinterest with friends?

Send them this page. It is free to read, no account needed.

More Pinterest Questions

Free preview

Every question in the Pinterest catalog gets this depth

What you just read — canonical solution, follow-up arc, what passing candidates actually did — exists for all 70 Pinterest questions, refreshed monthly from new candidate reports.

$59/mo — or $50/mo with the 3-month pass · cancel anytime
Pinterest · Coding · Reported 6× across candidate reports
Is this helpful?