← Pinterest Interview Insights

Pinterest·Software Engineer·Technical Phone Screen·Senior

SeniorPrefer not to say
May 2026Remote

Summary

Pinterest iOS engineering interview that was basically one big design problem: build a flood-fill app from scratch and talk through every layer of it. Covered UI architecture, data modeling, algorithm choices, and edge cases all in one shot. Felt more like a system design round than a coding screen.

Questions Asked (5)

Q1

Design and implement an iOS app that shows a 2D grid of colored cells. Tapping a cell should flood-fill all 4-directionally adjacent cells of the same color to the tapped cell's color.

System DesignAlgorithms & Data StructuresTechnical Trade-offs
Author's notes

This was the whole interview basically.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and constraints, then outline the high-level architecture (UI, model, and algorithm). Discuss the flood-fill algorithm (BFS/DFS) and its complexity, and address iOS-specific implementation details like rendering and touch handling. Finally, cover trade-offs and potential optimizations.

Pro tip: Mention that you would use an iterative BFS instead of recursive DFS to avoid stack overflow on large grids, and discuss how to handle edge cases like tapping a cell that already has the target color.

1. Clarify Requirements

Ask about grid size, color palette, performance expectations, and whether the grid is static or dynamic. Confirm that flood fill should only change cells of the original color.

2. High-Level Design

Outline the app architecture: a view to render the grid (e.g., UICollectionView or custom drawing), a model to store cell colors, and a controller to handle taps and coordinate the flood fill.

3. Algorithm Choice

Explain the flood-fill algorithm using BFS (queue) or DFS (stack) to traverse 4-directionally adjacent cells. Discuss time complexity O(N) where N is number of cells, and space complexity O(N) in worst case.

4. Implementation Details

Describe how to handle touch events, update the model, and efficiently refresh the UI (e.g., batch updates or invalidate only affected cells). Mention using a 2D array for the grid and a queue for BFS.

5. Trade-offs and Optimizations

Discuss trade-offs between BFS and DFS, recursive vs iterative, and potential optimizations like early termination if the new color equals the old color, or using a union-find structure for dynamic updates.

Key Points to Mention

  • BFS vs DFS: BFS is safer for large grids to avoid stack overflow; DFS is simpler but riskier.
  • Time and space complexity: O(N) time and O(N) space in worst case, where N is the number of cells.
  • Edge cases: tapping a cell already the target color (no-op), grid boundaries, and disconnected regions.
  • iOS specifics: using UICollectionView for grid rendering, handling touch via gesture recognizers or collection view delegate.
  • Performance considerations: minimizing UI updates by only refreshing changed cells, and using background threads for large grids.
  • Testing: unit tests for the flood-fill algorithm with various grid configurations and edge cases.

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

Q2

What data structure would you use to represent the grid, and why?

Algorithms & Data StructuresData Modeling
Author's notes

Went with a 2D array of enums for the cell color.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the grid's characteristics (dimensions, data type, sparsity) and the operations to be performed. Then propose a primary data structure (e.g., 2D array) and justify it based on access patterns, memory, and performance. Optionally, mention alternatives and trade-offs to show depth.

Pro tip: At Pinterest, grids often represent images or boards, so consider memory layout and cache efficiency; for sparse grids, a dictionary or coordinate list can save memory and improve performance.

1. Clarify requirements

Ask about grid size, data type, sparsity, and required operations (e.g., random access, updates, traversals).

2. Propose primary structure

Suggest a 2D array (list of lists) for dense grids, explaining its O(1) access and simplicity.

3. Justify with trade-offs

Discuss memory usage, cache locality, and performance for common operations compared to alternatives.

4. Consider alternatives

Mention sparse representations (dictionary, coordinate list) if the grid is sparse or if memory is a concern.

5. Conclude with recommendation

Summarize why the chosen structure best fits the given scenario, tying back to requirements.

Key Points to Mention

  • 2D array (list of lists) for dense grids: O(1) random access, simple implementation.
  • Sparse grid alternatives: dictionary with (row, col) keys or compressed sparse row (CSR) for memory efficiency.
  • Memory layout: row-major vs. column-major order affects cache performance.
  • Operations: access, update, traversal, and search complexities for each structure.
  • Trade-offs: memory overhead vs. speed, especially for large grids.
  • Pinterest context: grids for images/boards may benefit from optimized memory layout or sparse representations.

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

Q3

Walk through the flood-fill algorithm. Would you use iterative or recursive, and what are the time and space complexity trade-offs?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Recursive felt cleaner to explain but I knew stack overflow was the obvious trap on large grids so I pushed iterative with a queue.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clearly defining the flood-fill problem and the standard BFS/DFS approaches, then compare iterative and recursive implementations in terms of time and space complexity. Emphasize that the choice depends on constraints like grid size, recursion depth limits, and memory availability, and relate it to practical scenarios such as image processing at Pinterest.

Pro tip: Mention that recursion can cause stack overflow on large grids, so iterative BFS with an explicit queue is often safer in production, but recursive DFS is simpler and acceptable for small inputs. Also note that the space complexity of BFS is O(min(M,N)) for a grid, which is better than DFS's O(M*N) in the worst case.

1. Define the problem

Explain that flood-fill starts from a seed pixel and changes the color of all connected pixels of the same original color to a new color. Clarify that connectivity can be 4-directional or 8-directional.

2. Describe the algorithm

Outline the standard approach: check if the starting pixel already has the new color, then use a stack (DFS) or queue (BFS) to explore neighbors, changing colors as you go. Mention that you can also use recursion for DFS.

3. Compare iterative vs recursive

Discuss that recursion uses the call stack, which can overflow for large grids, while iteration uses an explicit data structure (stack or queue) that is heap-allocated and can handle larger inputs. Note that iterative BFS explores level by level, while recursive DFS goes deep first.

4. Analyze time and space complexity

State that time complexity is O(M*N) for an MxN grid since each pixel is visited once. Space complexity: recursive DFS is O(M*N) in the worst case due to call stack; iterative DFS with explicit stack is also O(M*N); iterative BFS with queue is O(min(M,N)) for a grid because the queue holds at most one diagonal's worth of nodes.

5. Conclude with trade-offs and recommendation

Summarize that iterative BFS is generally preferred for large grids due to bounded space and no stack overflow risk, while recursive DFS is simpler but risky for deep recursion. Mention that for small grids or when memory is not a concern, either is fine.

Key Points to Mention

  • Time complexity is O(M*N) because each cell is processed once.
  • Recursive DFS space complexity is O(M*N) in the worst case due to call stack depth.
  • Iterative BFS space complexity is O(min(M,N)) for a grid, which is more efficient.
  • Recursion can cause stack overflow for large grids, so iterative is safer in production.
  • BFS explores level by level and is often used for shortest path in unweighted graphs, but flood-fill doesn't require shortest path.
  • Edge cases: starting pixel already has the new color, empty grid, or disconnected regions.

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

Q4

How would you handle very large grids efficiently and avoid stack overflow?

Algorithms & Data StructuresSystem Design
Author's notes

Basically a follow-up to the algorithm question.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the grid size and constraints, then propose an iterative BFS/DFS with an explicit stack/queue to avoid recursion limits. Discuss memory optimizations like bit-packing, sparse representations, or chunked processing, and mention trade-offs between time and space.

Pro tip: Emphasize that you'd first ask about the grid's characteristics (e.g., density, access patterns) to choose the right data structure, showing you prioritize understanding the problem over jumping to code.

1. Clarify constraints and requirements

Ask about grid dimensions, memory limits, whether it's static or dynamic, and what operations are needed (e.g., traversal, search, update).

2. Choose iterative algorithms

Replace recursion with iterative BFS/DFS using an explicit stack or queue to prevent stack overflow and control memory usage.

3. Optimize memory representation

Use compact data structures like bitsets, sparse matrices, or run-length encoding; process the grid in chunks or stream rows to reduce memory footprint.

4. Consider distributed or external processing

If the grid is too large for a single machine, discuss partitioning, MapReduce, or using external memory (e.g., disk-based) algorithms.

5. Analyze trade-offs and test

Evaluate time vs. space complexity, cache performance, and scalability; propose testing with large synthetic grids to validate the approach.

Key Points to Mention

  • Iterative BFS/DFS with explicit stack/queue to avoid recursion depth limits
  • Memory-efficient data structures: bitsets, sparse matrices, run-length encoding
  • Chunking or streaming to process grid in blocks, reducing peak memory
  • Distributed processing frameworks (e.g., MapReduce) for grids exceeding single-machine memory
  • Time-space trade-offs and cache locality considerations
  • Edge cases: disconnected components, infinite loops, and boundary conditions

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

Q5

How would you implement reset and undo functionality for the grid?

System DesignTechnical Trade-offs
Author's notes

Undo tripped me up more than I expected.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the grid's data model and user interactions, then propose a command pattern with a history stack for undo and a snapshot or initial-state reference for reset. Discuss trade-offs between memory usage, performance, and complexity, and how to handle edge cases like concurrent edits or persistence.

Pro tip: Emphasize that undo/redo should be scoped to user actions, not every state change, and consider using a bounded history to prevent memory bloat—this shows you think about production constraints.

1. Clarify Requirements

Ask about the grid's scope (e.g., number of cells, edit types), expected undo depth, and whether reset should revert to initial state or last saved state.

2. Choose a Core Pattern

Propose the Command pattern for undo, where each user action is encapsulated as an object with execute and undo methods, and a history stack manages the sequence.

3. Design Reset Mechanism

For reset, either store a deep copy of the initial grid state or replay the inverse of all commands; discuss trade-offs between memory and computation.

4. Address Edge Cases and Performance

Handle scenarios like undoing after reset, batching rapid edits, limiting history size, and ensuring UI updates are efficient (e.g., using immutable data structures).

5. Discuss Trade-offs and Alternatives

Compare command pattern vs. state snapshots vs. event sourcing, and justify your choice based on memory, performance, and complexity.

Key Points to Mention

  • Command pattern with execute/undo methods for each user action
  • History stack (or two stacks for undo/redo) with bounded size
  • Snapshot or initial state reference for reset functionality
  • Memory vs. performance trade-offs (e.g., storing full snapshots vs. diffs)
  • Handling concurrent edits or collaborative scenarios (e.g., operational transforms)
  • Persistence of undo history across sessions (optional, based on requirements)

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