← Capital One Interview Insights

Capital One·Software Engineer·Online Assessment (OA)·Intermediate

Intermediate
Jul 2026

Summary

Capital One SWE interview with a grid simulation problem. Not the hardest thing I've ever seen but there are enough edge cases to trip you up if you're not careful about placement order and overlap logic.

Questions Asked (1)

Q1

Given integers n and m and an ordered list of figures (each being one of five predefined shapes), construct an n x m grid initialized to zero. For each figure in order, find the first valid top-left placement position in row-major order where the shape fits within bounds and doesn't overlap any already-placed cells. Fill those cells with the figure's 1-based index. If no valid placement exists, skip it. Return the final grid.

Algorithms & Data Structures
Author's notes

The shape definitions are handed to you so that part isn't the puzzle.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the five predefined shapes and their orientations, then simulate the placement process by iterating through each figure and scanning the grid in row-major order to find the first valid top-left position. For each candidate position, check if the shape fits within bounds and does not overlap existing cells; if valid, place the figure and update the grid, otherwise skip it.

Pro tip: Discuss how to optimize the placement search by precomputing the shape's bounding box and using a sliding window or early termination to avoid redundant checks, especially for large grids.

1. Clarify shapes and constraints

Confirm the exact definitions of the five shapes (e.g., their coordinates relative to top-left) and any orientation rules. Ensure you understand the grid dimensions and that placement must be within bounds and non-overlapping.

2. Design placement algorithm

For each figure in order, iterate through all possible top-left positions in row-major order. For each position, check if the shape fits within the grid and does not overlap any already-filled cells.

3. Implement validation and placement

Write a helper function to validate a placement at a given position. If valid, fill the corresponding cells with the figure's 1-based index and break to the next figure; if no valid position is found, skip the figure.

4. Analyze complexity and optimize

Discuss time and space complexity: O(n*m*k) per figure in the worst case, where k is the number of cells in the shape. Consider optimizations like precomputing shape offsets or using a more efficient search if needed.

5. Test with edge cases

Walk through examples including empty grid, shapes that exactly fit, shapes that cannot be placed, and multiple figures. Verify the row-major order and 1-based indexing.

Key Points to Mention

  • Row-major order scanning for placement positions
  • Bounds checking and overlap detection for each shape
  • 1-based indexing for filled cells
  • Skipping figures when no valid placement exists
  • Time complexity analysis and potential optimizations
  • Handling of predefined shapes and their orientations

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