← Pinterest Interview Insights

Pinterest·Software Engineer·Onsite - Coding / Algorithms·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Pinterest SWE coding round, three problems ranging from easy warmup to a genuinely tricky streaming design question. The set equality problem was a freebie but the sliding window ad ranking one had some teeth to it.

Questions Asked (3)

Q1

Given two integer arrays that may contain duplicates and aren't sorted, determine whether they represent the same set of unique elements.

Algorithms & Data Structures
Author's notes

Easiest of the three.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify that the problem asks whether the sets of unique elements are equal, not whether the arrays are identical. Then propose using hash sets to deduplicate each array and compare the resulting sets, discussing time and space complexity. If needed, also mention a sorting-based alternative that avoids extra space.

Pro tip: Always clarify the definition of 'same set' and edge cases (empty arrays, null inputs) before coding, and explicitly state that duplicates and order don't matter. This shows attention to detail and prevents misinterpretation.

1. Clarify the problem

Confirm that 'same set of unique elements' means the sets of distinct values are equal, ignoring duplicates and order. Ask about input constraints (e.g., null, empty arrays, integer range).

2. Choose an approach

Decide between a hash-set-based solution (O(n+m) time, O(n+m) space) and a sorting-based solution (O(n log n + m log m) time, O(1) extra space). Explain trade-offs.

3. Outline the algorithm

For hash sets: build a set from the first array, build a set from the second array, then check if the sets are equal. For sorting: sort both arrays, deduplicate in-place, then compare element by element.

4. Analyze complexity and edge cases

State time and space complexity for the chosen approach. Discuss edge cases: empty arrays, arrays with all duplicates, arrays of different lengths after deduplication, and null inputs.

5. Test with examples

Walk through a few examples, including positive and negative cases, to verify correctness. Mention potential pitfalls like integer overflow or hash collisions if relevant.

Key Points to Mention

  • Use of hash sets for O(n) average-case deduplication and comparison
  • Sorting-based alternative for O(1) extra space (if allowed to modify input)
  • Time and space complexity analysis for both approaches
  • Edge cases: empty arrays, null inputs, arrays with duplicates, different lengths
  • Clarification that order and duplicates are irrelevant
  • Potential follow-up: how to handle very large arrays or streaming data

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

Design a system to find the top K ads by impression count within a sliding time window, first as a batch query over a sorted event log, then as a streaming data structure supporting ingest and query operations.

Algorithms & Data StructuresSystem Design
Author's notes

This one took most of the interview.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements: define the sliding window semantics (event-time vs processing-time, inclusive/exclusive bounds), K, and whether the batch log is sorted by timestamp. For the batch case, propose a two-pointer sliding window over the sorted log with a hash map of counts and a heap or balanced BST for top-K; for streaming, propose a bucketed time-window structure with per-bucket counts and a global top-K tracker, discussing trade-offs between exactness and memory.

Pro tip: Explicitly call out the difference between event-time and processing-time windows and how out-of-order/late events are handled—this is a common production pitfall and shows you think beyond textbook algorithms.

1. Clarify requirements and constraints

Ask about window type (tumbling vs sliding, event-time vs processing-time), window size and slide, K, data volume, and whether approximate results are acceptable. Confirm the batch log is sorted by timestamp and define tie-breaking rules.

2. Design the batch solution

Use two pointers to maintain the current window over the sorted log, a hash map for per-ad counts, and a min-heap of size K (or a balanced BST) to track top-K. Explain how to update counts and the heap as the window slides, and analyze time/space complexity.

3. Design the streaming solution

Propose bucketed time windows: maintain per-bucket ad counts and a global top-K structure (e.g., heap or sorted map). On ingest, update the current bucket and top-K; on query, aggregate buckets in the window and return top-K. Discuss handling out-of-order events and late arrivals.

4. Compare trade-offs and optimize

Contrast exact vs approximate approaches (e.g., Count-Min Sketch, Space-Saving) for high-cardinality ad IDs. Discuss memory vs accuracy, update/query latency, and how to scale (sharding by ad ID, parallel aggregation).

5. Address edge cases and extensions

Cover empty windows, K larger than distinct ads, ties, and window boundary conditions. Mention extensions like multiple windows, weighted impressions, or distributed streaming (e.g., Kafka + Flink).

Key Points to Mention

  • Sliding window semantics: event-time vs processing-time, window size and slide, inclusive/exclusive bounds
  • Two-pointer technique for batch processing over sorted event log
  • Min-heap of size K for top-K tracking, with complexity O(N log K) batch and O(log K) per update streaming
  • Bucketed time-window structure for streaming with per-bucket counts and global top-K
  • Handling out-of-order/late events and watermarks in streaming
  • Approximate algorithms (Count-Min Sketch, Space-Saving) for memory-efficient top-K at scale

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

Can a target string be formed using characters from a source string, where each character in the source can only be used once?

Algorithms & Data Structures
Author's notes

Basically an anagram subset check.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

This is a classic anagram/frequency counting problem. Clarify that each character in the source can be used at most once, so the target is formable iff for every character, its frequency in the target is ≤ its frequency in the source. Present a solution using a hash map or fixed-size array to count characters, and analyze time and space complexity.

Pro tip: Mention that if the character set is known (e.g., ASCII), a fixed-size array of 256 integers is more efficient than a hash map, and you can early-exit if the target is longer than the source. Also, discuss how the solution changes if the source has limited characters or if the target is very large.

1. Clarify the problem

Confirm that each character in the source can be used only once, and that the order of characters does not matter. Ask about character set (e.g., ASCII, Unicode) and constraints.

2. Choose data structure

Decide between a hash map (general) or a fixed-size array (if character set is known). Explain the trade-offs in terms of time and space.

3. Count frequencies

Iterate through the source string and increment counts. Then iterate through the target string and decrement counts, checking that no count goes negative.

4. Analyze complexity

State that time complexity is O(n + m) where n and m are lengths of source and target, and space complexity is O(k) where k is the size of the character set.

5. Discuss edge cases

Mention cases like empty strings, target longer than source, and characters not present in source. Also, consider if the source can be modified or if multiple queries are needed.

Key Points to Mention

  • Frequency counting using hash map or array
  • Time complexity O(n + m) and space complexity O(k)
  • Early exit if target length > source length
  • Handling Unicode or large character sets
  • Edge cases: empty strings, repeated characters
  • Alternative approaches like sorting (O(n log n)) and why counting is better

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.