← Capital One Interview Insights

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

Intermediate
Apr 2026

Summary

Capital One software engineer assessment with four coding problems ranging from array pair counting to a segment tree style placement query. The problems were independent and algorithmic, no behavioral stuff from what I could tell. Mix of easy and genuinely hard.

Questions Asked (4)

Q1

Given an integer array, count the number of index pairs (i, j) where i < j and the values at both indices are equal. Expected O(n) time and O(n) space.

Algorithms & Data Structures
Author's notes

Classic frequency map problem.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a hash map to count the frequency of each value in a single pass, then sum the number of pairs for each value using the combination formula C(freq, 2). This achieves O(n) time and O(n) space. Alternatively, you can compute the count on the fly by adding the current frequency before incrementing it.

Pro tip: Clarify that the array may contain negative numbers or large values, so a hash map is preferred over an array-based frequency counter unless the value range is known to be small. Also, mention that the result can be large, so use a 64-bit integer to avoid overflow.

1. Understand the problem

Restate the problem: count pairs (i, j) with i < j and arr[i] == arr[j]. Confirm that the array can be unsorted and may contain duplicates.

2. Choose the right data structure

Select a hash map (dictionary) to store frequency counts because it provides O(1) average-time insertions and lookups, enabling an O(n) solution.

3. Design the algorithm

Iterate through the array once. For each element, add its current frequency to a running total (this counts new pairs formed with previous occurrences), then increment its frequency in the map.

4. Analyze complexity

Explain that the algorithm runs in O(n) time because each element is processed once, and uses O(n) space for the hash map in the worst case (all elements distinct).

5. Test with examples

Walk through a small example, such as [1,2,3,1,1,2], to verify the count and demonstrate correctness. Also consider edge cases like empty array or all identical elements.

Key Points to Mention

  • Hash map for frequency counting
  • Single-pass O(n) time complexity
  • O(n) space complexity due to hash map
  • Combination formula C(freq, 2) or incremental counting
  • Handling large counts with 64-bit integers
  • Edge cases: empty array, all elements same, negative numbers

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

Q2

Simulate a match-three style board game: repeatedly find all horizontal or vertical runs of 3+ identical letters, remove them, apply gravity so letters fall down, and repeat until no more removals. Return the final board state.

Algorithms & Data Structures
Author's notes

This one took me longer than I expected.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the rules and constraints first, then outline a simulation loop that repeatedly marks removable cells, clears them, and applies gravity until stable. Discuss how to efficiently detect runs and handle cascades, and analyze time/space complexity.

Pro tip: Mention that you can optimize by only rechecking rows/columns affected by gravity, and that using a sentinel or padding can simplify boundary checks.

1. Clarify requirements and constraints

Ask about board dimensions, letter set, whether diagonal matches count, and if new letters spawn. Confirm that gravity only moves letters down within columns.

2. Design the simulation loop

Outline a loop that scans for all horizontal and vertical runs of 3+ identical letters, marks them for removal, clears them, and then applies gravity. Repeat until no removals occur.

3. Implement run detection and marking

For each row and column, traverse and track consecutive identical letters. When a run length reaches 3, mark all cells in that run for removal (e.g., using a boolean matrix).

4. Apply gravity and cascade

After clearing marked cells, shift letters down in each column to fill empty spaces. Then repeat the detection and clearing until a full pass yields no removals.

5. Analyze complexity and edge cases

Discuss time complexity (e.g., O(R*C) per iteration, with multiple iterations) and space complexity. Mention edge cases like empty board, no matches, and full-board matches.

Key Points to Mention

  • Use a boolean matrix or set to mark cells for removal to avoid modifying the board during scanning.
  • Scan rows and columns separately for runs of 3 or more identical letters.
  • Apply gravity by compacting each column from bottom to top, preserving order.
  • Repeat the process until a full iteration produces no removals (fixed-point).
  • Time complexity is O(k * R * C) where k is the number of cascade iterations; space is O(R*C) for the board and marking structure.
  • Consider optimizations like only rechecking rows/columns affected by gravity, or using a queue of candidate positions.

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

Q3

Given an n x n matrix, check whether every cell on the main diagonal and anti-diagonal is nonzero, and every cell NOT on either diagonal is zero.

Algorithms & Data Structures
Author's notes

Straightforward.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem constraints and edge cases (e.g., n=1, n=2). Then, propose a single-pass O(n^2) solution that checks each cell's position relative to the diagonals, or an O(n) solution that directly verifies the required pattern by iterating over rows and columns. Discuss trade-offs and test with examples.

Pro tip: Mention that for n=1, the single cell is on both diagonals, so it must be nonzero; for n=2, every cell is on a diagonal, so all must be nonzero. This shows attention to edge cases.

1. Clarify requirements and edge cases

Ask if n can be 0 or 1, and confirm that 'main diagonal' means i==j and 'anti-diagonal' means i+j==n-1. Discuss what happens for small n.

2. Choose an approach

Decide between a straightforward O(n^2) check of every cell or a more efficient O(n) check that directly verifies the pattern by iterating over rows and columns.

3. Implement the solution

Write code that iterates through the matrix, checking each cell's condition based on its position. For O(n), check each row's diagonal elements and ensure all other elements are zero.

4. Test with examples

Run through small cases (n=1, n=2, n=3) and a larger case to verify correctness. Also test invalid matrices to ensure false is returned.

5. Analyze complexity

State the time and space complexity of your solution. For O(n^2), time is O(n^2) and space O(1); for O(n), time is O(n) and space O(1).

Key Points to Mention

  • Definition of main diagonal (i == j) and anti-diagonal (i + j == n - 1).
  • Edge cases: n=1 (cell on both diagonals, must be nonzero), n=2 (all cells on diagonals, all must be nonzero).
  • Time and space complexity trade-offs between O(n^2) and O(n) solutions.
  • In-place checking without modifying the matrix.
  • Handling of zero and nonzero values (e.g., negative numbers are nonzero).
  • Potential follow-up: what if the matrix is not square? (Problem states n x n, so assume square.)

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

Q4

Design a data structure for N positions (1 to N). Support two operations: mark a range [l, r] as occupied, and find the leftmost start of a contiguous unoccupied segment of length k. Both N and the number of queries can be up to 2x10^5, so aim for near O((N+Q) log N) total time.

Algorithms & Data StructuresSystem DesignTechnical Trade-offs
Author's notes

This is the one that hurt.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints and operations, then propose a segment tree that tracks for each segment the maximum contiguous free length, prefix free length, and suffix free length. For range marking, use lazy propagation to set segments as fully occupied. For finding the leftmost start of length k, traverse the tree preferring left children when they can accommodate k.

Pro tip: Mention that you would first consider a simpler approach like a sorted set of free intervals, but note its O(N) worst-case for merging; then justify the segment tree for guaranteed O(log N) per operation. This shows you evaluate trade-offs and understand amortized vs worst-case analysis.

1. Clarify requirements and constraints

Confirm that operations are online, N and Q up to 2e5, and that marking is idempotent. Discuss whether queries can overlap or if marks are permanent.

2. Choose data structure

Propose a segment tree over positions 1..N. Each node stores: max contiguous free length, prefix free length, suffix free length, and a lazy flag for full occupancy.

3. Define merge and lazy propagation

Explain how to combine children: prefix = left.prefix if left is fully free else left.prefix; suffix similarly; max = max(left.max, right.max, left.suffix + right.prefix). Lazy set to occupied updates node to all zeros.

4. Implement range update and query

For mark [l,r], recursively update with lazy propagation. For find leftmost k, recursively check left child's max >= k, else check crossing segment, else right child.

5. Analyze complexity and edge cases

State O(log N) per operation, O(N) build. Handle k > N, no available segment, and full occupancy. Discuss memory O(N).

Key Points to Mention

  • Segment tree node stores max, prefix, suffix free lengths
  • Lazy propagation for range assignment to occupied
  • Merge formula: max = max(left.max, right.max, left.suffix + right.prefix)
  • Query for leftmost k: traverse left-first, check crossing
  • Time complexity O((N+Q) log N), space O(N)
  • Alternative: sorted set of free intervals with O(N) worst-case merge

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