Pinterest logo

Pinterest Hard Interview Questions

3 hard-level practice questions for Pinterest technical interviews

Pinterest software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.

Software Engineer Backend Engineer Frontend Engineer Full Stack Engineer Mobile Engineer Data Engineer Data Scientist ML Engineer DevOps Engineer DevOps Engineer Product Manager SRE Security Engineer Engineering Manager Data Analyst UX/UI Designer QA Engineer
coding Hard Verified Question #1

1. Compressed Grid Operations


Category: Matrix coding problem
Design a CompressedGrid class that stores a sparse integer matrix efficiently by keeping only non-zero values in memory. The class must support...
Input: Matrix (2D array)
Output: Computed result
Want to practise this one?
Create a free account to open the full question and practise Pinterest questions with AI.
Sign up free
coding Hard Verified Question #2

2. Run Length Decode All


Category: Graph coding problem
A signal log is compressed using run-length encoding. In this scheme, a source string of digits is scanned left to right, and each run of identical...
Input: Graph (nodes and edges)
Output: Array
coding Hard binary search #1

1. [Binary Search] — Return the top K scores from a sorted 2D matrix


Background
Pinterest's Home Feed ranking needs to select high-scoring candidate Pins without sorting every candidate. This exercise models candidate scores as a two-dimensional matrix and adapts a reported Pinterest interview question about sorting a 2D array and returning its top K elements.
Problem statement
You are given a nonempty rectangular integer matrix scores. Each row is sorted in nondecreasing order from left to right, and each column is sorted in nondecreasing order from top to bottom.
Return the K largest entries in nonincreasing order. Each matrix cell is a separate entry: equal scores must appear multiple times if multiple such entries belong in the result. Return only score values, not cell coordinates. If k = 0, return an empty list.
You must not modify the input matrix or flatten it into another collection. Your algorithm must use O(1) auxiliary space, excluding the returned list, which may also serve as its working buffer. In particular, a separate heap, visited set, or array of row pointers whose size grows with the input is not allowed.
Target worst-case time is O((m + n) log(V + 1) + k log(k + 1)), where m and n are the matrix dimensions and V = maximum_score - minimum_score + 1. Standard library sorting is permitted only if its auxiliary-space guarantee meets the requirement.
Function or class signature
  • top_k_scores(scores: list[list[int]], k: int) -> list[int]


Example 1:
Input:
{"scores": [[1, 4, 7], [2, 5, 8], [3, 6, 9]], "k": 4}

Output:
[9, 8, 7, 6]

Explanation: The four largest entries are 9, 8, 7, and 6. The matrix is sorted along both dimensions, but concatenating its rows does not produce a sorted sequence.
Example 2:
Input:
{"scores": [[-5, -1, 2], [-3, 2, 2], [0, 2, 7]], "k": 3}

Output:
[7, 2, 2]

Explanation: There is one entry with score 7 and four entries with score 2. Only two of those four equal entries are needed; their coordinates do not matter because the output contains only values.
Constraints:
  • 1 <= m, n <= 200000, with m * n <= 2000000.

  • scores is rectangular and sorted along both dimensions as specified.

  • Each score is an integer in [-10^9, 10^9].

  • 0 <= k <= min(m * n, 200000).

  • The input is read-only; the returned list may contain at most k entries at any point.


Follow-up:
Now return (score, row, column) triples, ordered by descending score, then ascending row, then ascending column. How would you select entries tied at the cutoff and preserve the same time and auxiliary-space bounds?
Want to practise this one?
Create a free account to open the full question and practise Pinterest questions with AI.
Sign up free

Start practicing Pinterest questions

Sign up for free to access walkthroughs, AI-generated questions, and more.

Get Started Free