← Capital One Interview Insights

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

Intermediate
Jul 2026

Summary

Capital One OA for a software engineering role. Four problems, ranging from pretty straightforward to genuinely tricky. The bubble explosion one ate up most of my time and I'm still not sure I got the gravity part right.

Questions Asked (4)

Q1

Given an array of positive integers and an integer k >= 1, count how many elements in the array are exact powers of k. Handle the edge case where k equals 1 separately.

Algorithms & Data Structures
Author's notes

This was the warmup and I almost tripped on the k=1 case.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem and edge cases, especially k=1. Then outline an efficient algorithm: for k>1, repeatedly divide each element by k until it's no longer divisible, and check if the result is 1; for k=1, count elements equal to 1. Finally, discuss time and space complexity and potential optimizations.

Pro tip: Mention that for k>1, you can precompute powers of k up to the maximum array value and use a hash set for O(1) lookups, which is efficient for multiple queries. Also, explicitly handle k=1 as a special case to avoid infinite loops.

1. Clarify the problem and edge cases

Confirm that the array contains positive integers and k >= 1. Discuss the special case when k=1, where only elements equal to 1 are powers of 1.

2. Choose an algorithm for k > 1

For each element, repeatedly divide by k while divisible, then check if the final value is 1. Alternatively, precompute powers of k up to the maximum element and use a set for O(1) membership checks.

3. Handle k = 1 separately

When k=1, count the number of elements equal to 1, since 1^n = 1 for any n, and no other number is a power of 1.

4. Analyze complexity and optimize

Discuss time complexity: O(n log_k(max)) for division method, or O(n + log_k(max)) for precomputation. Space complexity: O(1) for division, O(log_k(max)) for precomputation. Consider trade-offs.

5. Test with examples and edge cases

Walk through examples like k=2, array=[1,2,4,8,16,3] and k=1, array=[1,1,2,3] to verify correctness. Also test with large numbers and k=1.

Key Points to Mention

  • Edge case k=1: only elements equal to 1 are powers of 1.
  • For k>1, an element is a power of k if repeated division by k yields 1.
  • Precomputing powers of k up to max(array) and using a hash set for O(1) lookups.
  • Time complexity: O(n log_k(max)) for division method, O(n + log_k(max)) for precomputation.
  • Space complexity: O(1) for division method, O(log_k(max)) for precomputation.
  • Handling large integers and potential overflow in other languages (though Python handles big ints).

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

Q2

On a planet where moon phases cycle every 8 days (indices 0 through 7), you're given the starting phase on day 1 and a list of month lengths for that year. For a given target date (month, day), compute the moon phase index on that date.

Algorithms & Data Structures
Author's notes

Off-by-one errors everywhere.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, compute the total number of days elapsed from day 1 of month 1 to the target date by summing the lengths of all preceding months and adding the target day minus 1. Then, add the starting phase index and take the result modulo 8 to get the phase index on the target date. Handle edge cases like invalid dates and ensure the calculation is efficient.

Pro tip: Clarify whether the starting phase is for day 1 (index 0) and confirm that month lengths are given in order. Also, mention that you can precompute prefix sums of month lengths for O(1) date queries if multiple queries are expected.

1. Understand the problem and inputs

Restate the problem: given a starting phase on day 1, month lengths, and a target date, find the phase index. Confirm the indexing: day 1 corresponds to the starting phase, and phases cycle every 8 days.

2. Compute days elapsed

Calculate the number of days from day 1 of month 1 to the target date. Sum the lengths of all months before the target month, then add (target day - 1).

3. Calculate phase index

Add the starting phase index to the days elapsed, then take modulo 8 to get the phase index on the target date. Ensure the result is in the range 0-7.

4. Handle edge cases and validate

Check for invalid dates (e.g., day exceeding month length, month out of range). Consider if the target date is day 1 of month 1: days elapsed = 0, phase = starting phase.

5. Optimize for multiple queries (optional)

If multiple queries are expected, precompute prefix sums of month lengths to answer each query in O(1) time after O(n) preprocessing.

Key Points to Mention

  • Modular arithmetic: use modulo 8 to wrap around the phase cycle.
  • Off-by-one errors: day 1 means 0 days elapsed, so subtract 1 from the day.
  • Prefix sums for efficient date-to-day conversion.
  • Edge cases: invalid dates, first day of year, last day of year.
  • Time complexity: O(m) for single query (m = number of months), O(1) with precomputation.
  • Space complexity: O(1) extra space, or O(m) for prefix sums if precomputing.

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

Q3

Simulate a bubble-explosion mechanic on an R x C grid: repeatedly find any 4-directionally connected group of the same color with size >= T, remove it (set to 0), then apply gravity so remaining cells fall to the bottom of their columns. Repeat until no more groups can be removed, then return the final grid.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This one genuinely stressed me out.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the grid as a 2D array and simulate the process in rounds: each round, scan for all groups of size >= T using BFS/DFS, mark them for removal, then apply gravity to each column. Repeat until a round removes nothing, then return the grid. Emphasize correctness, complexity, and edge cases.

Pro tip: Mention that you can optimize by only re-checking cells adjacent to removed groups in subsequent rounds, and clarify that gravity is applied after all removals in a round to match typical game mechanics.

1. Clarify rules and edge cases

Confirm whether removal happens simultaneously for all groups in a round, whether gravity is applied after each removal or after all removals, and how to handle T <= 1 or empty grids.

2. Design group detection

Use BFS/DFS to find 4-directionally connected components of the same color. Track visited cells to avoid re-processing, and collect groups with size >= T.

3. Implement removal and gravity

Set all cells in qualifying groups to 0, then for each column, compact non-zero cells downward (stable order). This can be done in-place with a write pointer.

4. Loop until stable

Repeat detection and removal/gravity until a full pass finds no removable groups. Return the final grid.

5. Analyze complexity and optimize

Discuss time complexity O(R*C) per round, worst-case O(R*C * rounds). Suggest optimizations like only re-checking affected columns/cells or using union-find for dynamic connectivity.

Key Points to Mention

  • Use BFS/DFS for connected component detection with a visited matrix.
  • Apply gravity per column by shifting non-zero cells to the bottom, preserving relative order.
  • Process all removals in a round before applying gravity to avoid order-dependent artifacts.
  • Terminate when a full scan finds no groups of size >= T.
  • Time complexity: O(R*C) per round, potentially O(R*C * min(R,C)) worst-case; space O(R*C).
  • Edge cases: T=1 (removes all same-color connected cells), no groups, full grid removal, single row/column.

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

Q4

Given an array of N numeric strings of equal length L (leading zeros allowed), count unordered pairs where one string can be transformed into the other using at most two character swaps within a single string. Analyze time and space complexity.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The problem statement asked me to also define the transformation rule and state necessary conditions, which felt unusual for a coding problem.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a hash map to group strings by a canonical signature that is invariant under up to two swaps, then count pairs within each group. For each string, generate all possible strings reachable by 0, 1, or 2 swaps and use the lexicographically smallest as the key. This reduces the problem to counting pairs in groups, which can be done in O(N) time after O(N * L^2) preprocessing.

Pro tip: Mention that generating all 2-swap variants naively is O(L^4), but you can optimize to O(L^2) by considering only swaps that affect mismatched positions relative to a reference string. Also, clarify that unordered pairs mean each pair counted once, so use combinations.

1. Understand the problem and constraints

Clarify that strings are of equal length L, leading zeros allowed, and we need unordered pairs where one can be transformed into the other with at most two swaps. Confirm that swaps are within a single string.

2. Define a canonical representation

For each string, generate all strings reachable by 0, 1, or 2 swaps and choose the lexicographically smallest as its canonical key. This ensures two strings are in the same group iff they are transformable into each other.

3. Optimize canonical key generation

Instead of generating all O(L^4) swap combinations, note that only swaps involving mismatched positions relative to a reference string matter. This reduces to O(L^2) per string by considering at most two swaps among mismatched indices.

4. Count pairs using a hash map

Use a hash map to count frequencies of each canonical key. For each group of size k, add k*(k-1)/2 to the total count of unordered pairs.

5. Analyze time and space complexity

Time: O(N * L^2) for generating keys (assuming optimized swap generation) plus O(N) for hashing and counting. Space: O(N * L) for storing keys and the hash map. Mention that L is typically small, so this is efficient.

Key Points to Mention

  • Canonical form via minimum lexicographic string among all 2-swap variants
  • Optimization: only consider swaps among mismatched positions relative to a reference string
  • Use of hash map to group strings and count combinations
  • Time complexity: O(N * L^2) with optimization, space O(N * L)
  • Edge cases: strings already equal (0 swaps), strings differing by one swap, and strings requiring two swaps
  • Unordered pairs: use combinations formula k*(k-1)/2

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