← Pinterest Interview Insights

Pinterest·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Pinterest SWE interview with a grid simulation problem involving lighthouses, mirrors, and walls. Pretty niche problem type, not your typical graph traversal, and the cycle detection piece is where things get interesting.

Questions Asked (1)

Q1

Given a 2D grid containing lighthouses, walls, mirrors, and empty cells, determine how many cells are illuminated. Lighthouses emit rays in all four cardinal directions, mirrors reflect rays 90 degrees, walls block rays, and a cell is illuminated if any ray passes through it.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The mirror reflection logic tripped me up more than I expected.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints and edge cases first, then propose a solution that simulates ray propagation from each lighthouse using BFS/DFS while handling mirrors and walls. Discuss trade-offs between simulation and precomputation, and analyze time/space complexity.

Pro tip: Mention that you would use a visited set with direction to avoid infinite loops caused by mirrors, and consider early termination when all cells are illuminated.

1. Clarify requirements and constraints

Ask about grid size, number of lighthouses, mirror types (e.g., / and \), and whether rays can pass through lighthouses. Confirm if illumination includes the lighthouse cells themselves.

2. Choose representation and algorithm

Represent the grid and use BFS/DFS from each lighthouse, propagating rays in four directions. For mirrors, change direction based on mirror orientation; for walls, stop propagation.

3. Handle cycles and efficiency

Use a visited set of (row, col, direction) to prevent infinite loops. Consider processing all lighthouses simultaneously or using a queue to avoid redundant work.

4. Analyze complexity and trade-offs

Discuss time complexity O(L * R * C) in worst case, and space O(R * C). Mention potential optimizations like precomputing mirror reflections or using bitmasks for directions.

5. Test with edge cases

Walk through examples: no lighthouses, lighthouses surrounded by walls, mirrors creating loops, and large grids to ensure scalability.

Key Points to Mention

  • Use BFS/DFS with direction state to simulate ray propagation.
  • Handle mirrors by changing direction: '/' reflects right->up, up->right, etc.; '\' reflects right->down, down->right, etc.
  • Walls block rays; empty cells and lighthouses are illuminated if a ray passes through.
  • Avoid infinite loops with a visited set of (row, col, direction).
  • Time complexity: O(L * R * C) where L is number of lighthouses; can optimize by processing all rays in one pass.
  • Space complexity: O(R * C) for visited and illuminated sets.

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