def count_unique_posts_by_policy(records: list, policy: str) -> int:
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: ...
policy. An unknown policy gives 0.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.
Six reports between February and September 2026, from phone screens and onsite coding rounds, so it is one of the more repeated Pinterest coding questions. The fullest phone-screen report lists five small questions over a log sorted by timestamp and says test cases had to run live. That candidate explained each idea, coded after the interviewer agreed, finished and tested the first three, and only explained the last two before time ran out; they expected a reject but had no result when they posted. A reply in that thread says another candidate wrote all five parts and still waited a week for a result. Another phone-screen report gives three questions over (pinId, policy, date) records, says pin ids repeat and need deduping, and says the interviewer gave no hints and left the return values to the candidate; that screen was failed. A third candidate's phone screen was this question with a simple follow-up they could not recall, and they went on to the onsite. In onsite reports it appears as a coding round: one says it had two parts (a hash-map pass, then binary search), one says the candidate did the first three parts, and one names it Violation Log Analyzer. A separate onsite report describes a binary search over a log sorted by date string, where a bug the candidate could not fix hurt the round; it may be this question.
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.
Also reported as Pins Violation Log · Violation Log Analyzer · Log Violation Analysis
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: ...
policy. An unknown policy gives 0.Part 2 — policies a post violated
def policies_for_post(records: list, post_id) -> set: ...
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: ...
timestamp.Part 4 — unique posts in a time range
def count_unique_posts_in_range(records: list, start, end) -> int: ...
[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: ...
[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.
Count the unique posts in a time range on the sorted log
Count violations by policy in a time range; one report asks for unique pins per policy in the range instead
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.
If you have had this round, tell us how close this page was. It is how we keep the pages accurate.
Send them this page. It is free to read, no account needed.
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.