The Capital One Online Assessment (OA) tests candidates on fundamental programming skills, algorithmic thinking, and implementation accuracy. This article covers four reported Capital One OA coding questions from an assessment completed on CodeSignal, with an approximate time limit of 70 minutes.
The four problems cover array simulation, divisibility checks, Manhattan distance, and subarray pair counting. Although the solutions do not necessarily require advanced algorithms, candidates must understand the problem requirements, translate them into code, and handle edge cases correctly under time pressure.
Capital One OA Coding Questions at a Glance
| Problem | Key Concepts | Main Approach |
|---|---|---|
| T1: Arithmetic Operation Validation | Arrays, conditional logic | Calculate and compare each element |
| T2: Song and Animation Matching | Divisibility, string parsing | Check duration constraints |
| T3: Diamond-Shaped Matrix Regions | 2D arrays, Manhattan distance | Enumerate centers and target cells |
| T4: Counting Subarrays with at Least k Fruit Pairs | Hash Map, subarrays | Enumerate subarrays and maintain pair counts |
These problems focus primarily on implementation. T1 and T2 involve straightforward conditions, T3 requires careful coordinate calculations, and T4 requires tracking element frequencies while expanding a subarray.
T1: Arithmetic Operation Validation
Problem Description
You are given three integer arrays of equal length and an operator array containing only addition and subtraction symbols.
For each index, apply the corresponding operator to the elements from the first two arrays. Compare the result with the element at the same index in the third array.
If the calculated value matches the corresponding element, return true for that position. Otherwise, return false. The final output should be an array containing the results in their original order.
Solution Approach
This problem can be solved with a single array traversal.
Start at index 0 and iterate through the arrays. If the current operator is +, calculate a[i] + b[i]. If the operator is -, calculate a[i] - b[i].
Compare the calculated value with c[i] and append the Boolean result to the output array. After processing every index, return the completed array.
Complexity Analysis
Let n be the length of each array.
-
Time complexity:
O(n), because each position is processed once. -
Space complexity:
O(n)for the output array.
The main consideration is implementing the arithmetic operation exactly as specified. In particular, subtraction must preserve the correct operand order.
T2: Matching Songs with Animation Durations
Problem Description
You are given a list of songs and a list of animations. Each item contains a name and a duration, represented as a name-duration pair.
For each song, find an animation whose duration does not exceed the song's duration and divides it evenly. This ensures that the animation can repeat a whole number of times and finish at the same time as the song.
For example, if a song lasts 185 seconds and an animation lasts 37 seconds, the animation must play five times to match the song's duration.
The result should contain the selected animation name and the number of repetitions required, following the output format specified in the problem.
Solution Approach
First, parse each song and animation entry to extract its name and duration.
Then, iterate through the songs and check the available animations. For a song duration songDuration and an animation duration animationDuration, the following conditions must hold:
animationDuration <= songDurationsongDuration % animationDuration == 0
The first condition prevents the animation from exceeding the song's duration. The second ensures that the animation fits the song's duration exactly.
When a match is found, calculate the repetition count using:
repeatCount = songDuration / animationDuration
Store the required animation information in the result. If multiple animations satisfy the conditions, follow the problem's specified selection rule rather than assuming that any valid match can be returned.
Complexity Analysis
Let n represent the number of songs and m represent the number of animations.
If every song is checked against every animation, the time complexity is O(n × m). If the input is large, indexing animations by duration may help reduce unnecessary comparisons.
The key is to distinguish between an animation that is shorter than a song and one whose duration divides the song duration evenly. Both conditions must be satisfied.
T3: Finding Diamond-Shaped Regions in a Matrix
Problem Description
You are given a 2D matrix and an integer radius r. For every cell in the matrix, treat that cell as the center of a diamond-shaped region and collect all cells that satisfy the required distance condition.
Let the center cell have coordinates (centerX, centerY) and a target cell have coordinates (cellX, cellY). A target cell belongs to the region if:
abs(centerX - cellX) + abs(centerY - cellY) + 1 <= r
Repeat this process for every cell in the matrix and return the collected regions in the required format.
Solution Approach
The distance calculation uses Manhattan distance, which measures the sum of the absolute differences between two coordinates. Unlike Euclidean distance, it does not calculate the straight-line distance between two points.
A straightforward solution uses nested enumeration.
- Iterate through every row and column, treating the current cell as the center.
- For each center, traverse every cell in the matrix.
- Calculate the Manhattan distance between the center and the target cell, then add
1. - If the result is less than or equal to
r, include the target cell in the current region. - Repeat until every cell has been processed as a center, then return the results.
This approach follows the problem's definition directly and is relatively easy to implement and verify.
Complexity Analysis
Suppose the matrix contains n rows and m columns.
There are n × m possible center cells, and each center requires checking all n × m cells. Therefore:
-
Time complexity:
O(n² × m²). - Space complexity: Depends on the size of the returned regions. Storing all collected cells may require substantial memory.
Pay close attention to the distance formula and matrix boundaries. Every target coordinate must remain within the valid row and column ranges.
T4: Counting Subarrays Containing at Least k Pairs of Identical Fruits
Problem Description
You are given an integer array fruits, where each value represents a fruit type, and an integer k.
Your task is to count the number of contiguous subarrays that contain at least k pairs of identical fruits.
Each pair must consist of two fruits of the same type, and each fruit can belong to only one pair.
For example, three occurrences of the same fruit can form one pair, while four occurrences can form two pairs. Therefore, if a fruit appears frequency times, it contributes:
floor(frequency / 2)
The total number of pairs is the sum of the contributions from all fruit types in the subarray.
Solution Approach
A straightforward solution enumerates every possible contiguous subarray while using a Hash Map to track fruit frequencies.
Fix the left endpoint left with an outer loop. Then, use an inner loop to extend the right endpoint right one position at a time.
Whenever a new fruit enters the current subarray, update its frequency in the Hash Map. Maintain an additional variable, pairs, to track the total number of pairs without recalculating the contribution of every fruit type.
The key observation is that a new pair is formed only when the frequency of a particular fruit changes from an odd number to an even number.
For example:
- Frequency changes from 0 to 1: no new pair.
- Frequency changes from 1 to 2: add one pair.
- Frequency changes from 2 to 3: no new pair.
- Frequency changes from 3 to 4: add one pair.
After each expansion, check whether pairs >= k. If the condition holds, increment the answer because the current subarray qualifies.
Do not stop expanding the right endpoint as soon as a valid subarray is found. The task is to count all qualifying subarrays, and longer subarrays may also satisfy the condition.
Complexity Analysis
Let n be the length of the array.
There are O(n²) possible contiguous subarrays. Since each expansion requires only a frequency update and a constant-time check, the overall complexity is:
-
Time complexity:
O(n²). -
Auxiliary space complexity:
O(n)for the Hash Map.
The important optimization is maintaining the pair count incrementally. Tracking the number of occurrences alone is not sufficient because occurrences and valid pairs are different quantities.
How to Prepare for the Capital One OA
1. Practice Common Coding Patterns
These four questions cover several foundational problem-solving techniques:
- Arrays: Traversal, element-by-element calculations, and result collection.
- String Parsing: Extracting names and numeric values from formatted input.
- Math: Divisibility, modulo operations, and distance calculations.
- Matrices: Nested traversal and coordinate-based conditions.
- Hash Maps: Frequency counting and incremental state updates.
- Subarrays: Fixing a left endpoint, expanding a right endpoint, and counting valid ranges.
Rather than memorizing individual solutions, practice converting problem statements into clear conditions and choosing an appropriate data structure.
2. Practice Under a Time Limit
If your assessment has a time limit of approximately 70 minutes, aim to complete the more straightforward problems efficiently and reserve enough time for questions that require nested enumeration or state tracking.
After implementing each solution, leave time to check the logic and test edge cases. A brute-force solution can be a useful starting point, but always compare its complexity with the input constraints before submitting it.
3. Pay Attention to Edge Cases
Several details in this question set are easy to overlook:
- Arithmetic operations must use the correct operand order.
- An animation duration must divide the song duration evenly.
- The matrix region condition includes an additional
+1. - Fruit pairing requires integer division, with every two identical fruits forming one pair.
Before submitting, test small inputs, repeated values, cases with no valid matches, odd fruit frequencies, and cells near matrix boundaries.
These checks can reveal errors that are not obvious from the main examples.
4. Reimplement Solutions Without Looking at the Answer
Reading a solution is not the same as being able to write it during an assessment.
After reviewing a problem, close the reference solution and implement it again from scratch. For the fruit-pair problem in particular, make sure you can explain why the pair count increases only when a fruit's frequency changes from odd to even.
Understanding the reason behind each update makes it easier to handle variations of the same problem.
Final Thoughts
This set of Capital One OA coding questions focuses on foundational algorithms and implementation accuracy. The main topics are array simulation, divisibility checks, Manhattan distance, and subarray pair counting.
The first two problems have relatively direct solutions, while the matrix and subarray problems require more attention to enumeration boundaries and state management.
When preparing for the Capital One OA, prioritize understanding the problem requirements, selecting a suitable approach, and testing edge cases. A clear and correct implementation is a strong starting point for solving these types of coding questions under time pressure.
Capital One OA FAQ
How difficult is the Capital One OA?
The difficulty varies by role, hiring cycle, and assessment version. Coding questions may cover arrays, strings, mathematical operations, Hash Maps, and basic algorithmic techniques. Candidates should focus on understanding the requirements, handling edge cases, and writing correct code within the time limit.
How many coding questions are on the Capital One OA?
The number of questions depends on the specific assessment. The set discussed in this article contains four coding problems with an approximate time limit of 70 minutes. This does not mean every Capital One OA has exactly four questions. Always check the instructions provided with your assessment invitation.
What topics should I practice for the Capital One OA?
Start with Array, String, Hash Map, Sorting, Two Pointers, Prefix Sum, and basic math problems. Depending on the target role, you may also need to practice Graph, Tree, Heap, and Dynamic Programming problems.
Can I use brute force for the Capital One OA?
A brute-force solution may work when the input size is small, but its performance depends on the constraints and time limit. Before submitting, estimate the time complexity and determine whether the solution can process the largest expected input efficiently. If necessary, reduce repeated calculations or use a more suitable data structure.
Top comments (0)