PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Pinterest

Solve set equality and ad log top‑K

Last updated: Apr 16, 2026

Quick Overview

This multi-part question evaluates set and multiset operations, frequency counting, top-K computation over time windows, sliding-window and streaming data structures, and character-multiset matching for string construction within the coding & algorithms domain.

  • medium
  • Pinterest
  • Coding & Algorithms
  • Software Engineer

Solve set equality and ad log top‑K

Company: Pinterest

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

### Problem Set (Coding) #### 1) Check whether two sets are equal You are given two integer arrays `A` and `B` that represent **sets**, except they may contain duplicates and are not sorted. Return `true` if they represent the same mathematical set (same unique elements), otherwise return `false`. **Example** - `A = [1,2,2,3]`, `B = [3,1,2]` → `true` - `A = [1,2]`, `B = [1,2,4]` → `false` **Constraints** - `0 <= len(A), len(B) <= 2e5` - Values fit in 32-bit signed integer. --- #### 2) Top-K ads from impression logs + sliding window ingestion You are given an impression log as a list of events: - `events[i] = (timestamp_ms, ad_id)` - `events` is sorted by `timestamp_ms` ascending. **Part 1 (batch):** Given `events`, a window size `W_ms`, and an end time `T_end`, return the **top K ad IDs by number of impressions** whose timestamps fall in `[T_end - W_ms, T_end]`. Break ties by smaller `ad_id` (or specify a deterministic rule). **Part 2 (streaming):** Implement a data structure with two operations: - `ingestImpression(timestamp_ms, ad_id)` - `getTopK(T_end, W_ms, K)` such that it efficiently supports a sliding window query over recent impressions. Assume `ingestImpression` timestamps are non-decreasing. --- #### 3) Can a target string be formed from a source string? Given two strings `source` and `target`, determine if you can form `target` using characters from `source`. - Each character in `source` can be used **at most once**. - Return `true` if possible, else `false`. **Example** - `source = "aab"`, `target = "aba"` → `true` - `source = "ab"`, `target = "abb"` → `false` **Constraints** - Strings consist of ASCII letters (you may assume lowercase `a-z` if you want to simplify). - Length up to `2e5`.

Quick Answer: This multi-part question evaluates set and multiset operations, frequency counting, top-K computation over time windows, sliding-window and streaming data structures, and character-multiset matching for string construction within the coding & algorithms domain.

Related Interview Questions

  • Design Hierarchical Permission Checks - Pinterest (medium)
  • Implement weighted random choice - Pinterest (medium)
  • Solve five hard algorithm problems - Pinterest
  • Sample a string by real-valued scores - Pinterest (hard)
  • Find First Prefix-Matching Word - Pinterest (medium)
Pinterest logo
Pinterest
Nov 11, 2025, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
16
0

Problem Set (Coding)

1) Check whether two sets are equal

You are given two integer arrays A and B that represent sets, except they may contain duplicates and are not sorted.

Return true if they represent the same mathematical set (same unique elements), otherwise return false.

Example

  • A = [1,2,2,3] , B = [3,1,2] → true
  • A = [1,2] , B = [1,2,4] → false

Constraints

  • 0 <= len(A), len(B) <= 2e5
  • Values fit in 32-bit signed integer.

2) Top-K ads from impression logs + sliding window ingestion

You are given an impression log as a list of events:

  • events[i] = (timestamp_ms, ad_id)
  • events is sorted by timestamp_ms ascending.

Part 1 (batch): Given events, a window size W_ms, and an end time T_end, return the top K ad IDs by number of impressions whose timestamps fall in [T_end - W_ms, T_end].

Break ties by smaller ad_id (or specify a deterministic rule).

Part 2 (streaming): Implement a data structure with two operations:

  • ingestImpression(timestamp_ms, ad_id)
  • getTopK(T_end, W_ms, K)

such that it efficiently supports a sliding window query over recent impressions.

Assume ingestImpression timestamps are non-decreasing.

3) Can a target string be formed from a source string?

Given two strings source and target, determine if you can form target using characters from source.

  • Each character in source can be used at most once .
  • Return true if possible, else false .

Example

  • source = "aab" , target = "aba" → true
  • source = "ab" , target = "abb" → false

Constraints

  • Strings consist of ASCII letters (you may assume lowercase a-z if you want to simplify).
  • Length up to 2e5 .

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Pinterest•More Software Engineer•Pinterest Software Engineer•Pinterest Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.