Free beta: free to use with daily limits while we build. Join the waitlist for founding-member pricing at launch. Join the waitlist

Sign up free

Pinterest interview question

Track the top-scoring pin a user has viewed within a recent time window

Company:
Pinterest
Type:
Coding
Difficulty:
Medium
Reported:
November 18, 2026

Problem

Each pin has a trending score. Build a feature that keeps track of all the pins a user has seen in the last week and, at any given time, returns the top trending pin among those the user has viewed. The original also illustrates the window as the last 24 hours, so confirm its length. The window could later be changed (for example to 5 minutes, 5 hours or 5 days), which requires timestamps on each view.

Implement:

  1. add_new_pin(pin_id, score, timestamp): add a viewed pin to the running list.
  2. remove_expired_pin(now): make sure the top-scoring pin that will be returned is not outside the time range, by checking the top pin's time against the current time and removing it if needed.
  3. get_top_scoring_pin(now): return the top-scoring pin in the window as (pin_id, score), or None if there is none.

In this version the window length is a constructor argument. Whether a view exactly one window old still counts, whether the current time can move backwards between calls, how repeated views of the same pin are treated, and whether a pin's score can change are not stated; ask the interviewer.

Example 1

Input: pin_scores = [{"981292206280418755": 50}, {"981292206280418756": 35},
                     {"981292206280418757": 91}, {"981292206280418758": 92},
                     {"981292206280418759": 3},  {"981292206280418760": 88},
                     {"981292206280418761": 34}, {"981292206280418762": 9},
                     {"981292206280418763": 77}, {"981292206280418764": 55}]
       each added at time 0; get_top_scoring_pin(now=10)
Output: ("981292206280418758", 92)

All views are inside the week, and 92 is the highest score.

Example 2

Input: window = 604800 seconds (one week); add ("p1", 92, 0) and ("p2", 91, 100); get_top_scoring_pin(now=604850)
Output: ("p2", 91)

The view of p1 is older than one week (604,800 seconds) and is removed; p2 is still inside the window.

Constraints

  • Not stated; ask the interviewer.

Reported by candidates or drawn from publicly available sources, and rewritten in our own words. Pathwise Prep does not publish confidential assessment content. Report a concern