FastPrepUnique Active Pins by Time Segment
Problems/Unique Active Pins by Time Segment

Unique Active Pins by Time Segment

Pinterest logoPinterest● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Pinterest onsite interview. The report keeps pin logs with a start and an end, a sweep over any timestamps, and a follow-up that needs the count of distinct pins when several users create overlapping intervals for the same pin. We chose half-open intervals, how each row is written from the events, keeping gaps with a count of zero, the limits, and the examples, only so that the final reported follow-up can run. Our version is about 95% the same as the reported follow-up.

You are given interaction logs in an integer matrix logs. Each row [pinId, startTime, endTime] means that one user interaction keeps pinId active throughout the half-open interval [startTime, endTime).

Return the number of distinct active pins for every event-defined time segment. Let t0 < t1 < ... < tm be all distinct start and end timestamps. For every adjacent pair, return one row [ti, ti+1, count], where count is the number of distinct pin IDs active throughout [ti, ti+1).

  • Include segments whose count is zero.
  • Do not merge adjacent segments, even when their counts are equal.
  • Several logs for the same pin may overlap. That pin contributes only one to the distinct count while at least one of its intervals is active.

Function

uniqueActivePinTimeline(logs: int[][]) → int[][]

Examples

Example 1

logs = [[1,0,3],[2,1,2]]return = [[0,1,1],[1,2,2],[2,3,1]]

Pin 1 is active for the entire range. Pin 2 raises the distinct count only on [1,2).

Example 2

logs = [[7,0,4],[7,2,6],[8,3,5]]return = [[0,2,1],[2,3,1],[3,4,2],[4,5,2],[5,6,1]]

The two overlapping interactions for pin 7 still count as one distinct pin. Pin 8 makes the count two on [3,5).

Example 3

logs = [[1,0,1],[2,3,4]]return = [[0,1,1],[1,3,0],[3,4,1]]

No pin is active in the event-defined gap [1,3), so that segment is retained with count 0.

Constraints

  • 1 <= logs.length <= 200000.
  • Each row contains exactly three integers [pinId, startTime, endTime].
  • 1 <= pinId <= 10^9.
  • -10^9 <= startTime < endTime <= 10^9.

More Pinterest Onsite Interview questions

  • Minimum Bus Routes to a DestinationPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Delete and Compact a Forest SubtreePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Filter Pins by Excluded IDsONSITE INTERVIEW · Seen Oct 2026
  • Top-Scoring Items in a Time WindowONSITE INTERVIEW · Seen Oct 2026
  • Optimal Account BalancingPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Escape Room LeaderboardPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Policy Violation Set ChecksONSITE INTERVIEW · Seen Sep 2026
  • Shortest Sequence of Source SubsequencesONSITE INTERVIEW · Seen Sep 2026
  • Insert Addition and Multiplication OperatorsONSITE INTERVIEW · Seen Sep 2026
  • Coin ChangeONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Peak Process MemoryNutanix · ONSITE INTERVIEWNutanix interview questions
  • Calendar Event System with Pagination and IntersectionLead Bank · ONSITE INTERVIEWLead Bank interview questions
  • Top Error Types in a Time WindowNotion · ONSITE INTERVIEWNotion interview questions
  • Highlight and Rank Overlapping CitationsHarvey · PHONE SCREEN · ONSITE INTERVIEWHarvey interview questions
  • Worker Management with Promotions and Double-Paid TimeInstacart · ONSITE INTERVIEWInstacart interview questions
  • Merchant Capacity Interval MergeDoorDash · PHONE SCREENDoorDash interview questions
  • Free Time for Every Meeting RoomScale AI · PHONE SCREENScale AI interview questions
  • Merge Collinear Point SegmentsApplied Intuition · PHONE SCREENApplied Intuition interview questions
  • Worker Management (Promotion Track), Part 4: Full-Shift Double PayAirbnb · OAAirbnb interview questions
  • Lab and Consultation Appointment MatchingAssort Health · PHONE SCREENAssort Health interview questions

Pinterest interview experiences

  • Pinterest Experienced MLE Phone Screen: 1 Experience
All Pinterest interview questionsSee Pinterest hiring insights
Saved
class Solution {
    public int[][] uniqueActivePinTimeline(int[][] logs) {
        // write your code here
    }
}
Checking account…