← Capital One Interview Insights

Capital One·Machine Learning Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Capital One ML Engineer interview with two coding problems. The grid one was genuinely tricky and I'm not sure I fully nailed it, but the second felt more approachable once I saw the pattern.

Questions Asked (2)

Q1

Given an m x n grid where each cell is either a digit or an operator ('+' or '-'), find the maximum value achievable by any path from the top-left to the bottom-right (moving only right or down) such that the concatenated cells form a valid alternating digit-operator expression evaluated left to right.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This one took me a while to even parse correctly.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints and define the state for dynamic programming: position (i, j), last operator, and current accumulated value. Then derive a recurrence that considers moving right or down, updating the value based on whether the next cell is a digit or operator, and finally compute the maximum value at the bottom-right cell.

Pro tip: Discuss the trade-offs between dynamic programming and brute-force, and mention how you would handle large grids or negative numbers, showing awareness of scalability and edge cases.

1. Clarify the problem

Ask questions to confirm the rules: Can the path start with an operator? How are multi-digit numbers handled? Are there constraints on grid size? This ensures you understand the problem fully before solving.

2. Define the DP state

Identify that the state must capture the current cell, the last operator (if any), and the current accumulated value. Since the value can be large, consider if it can be bounded or if we need to store it explicitly.

3. Derive the recurrence

For each cell, consider the possible previous cells (top and left). If the current cell is a digit, update the value by appending the digit (value = value*10 + digit) if the last token was a digit, or by applying the pending operator if the last token was an operator. If the current cell is an operator, store it as the pending operator without changing the value.

4. Handle initialization and boundaries

Initialize the DP at the top-left cell. If it's a digit, the value is that digit; if it's an operator, the expression is invalid (unless the problem allows it). Handle edge cases like single-cell grids or grids with no valid path.

5. Compute and return the result

Iterate through the grid, filling the DP table. At the bottom-right cell, find the maximum value among all valid states. If no valid expression exists, return an appropriate indicator (e.g., -1 or null).

Key Points to Mention

  • Dynamic programming with state including position, last operator, and accumulated value.
  • Time and space complexity: O(m*n*V) where V is the number of possible values, which may be large; discuss optimizations or alternative approaches.
  • Handling of multi-digit numbers: concatenation of consecutive digits forms a number.
  • Edge cases: grid with only operators, no valid path, negative intermediate values, and large numbers.
  • Trade-offs: DP vs. brute-force path enumeration; potential for memoization or pruning.
  • Validation of the alternating pattern: ensuring digits and operators alternate correctly.

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

Q2

Given an integer array, count the total number of contiguous subarrays where adjacent elements always alternate between even and odd (sawtooth subarrays), with single-element subarrays counting as valid.

Algorithms & Data Structures
Author's notes

Much cleaner than the first problem.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a linear scan to track the length of the current alternating subarray ending at each position. For each element, if it alternates with the previous element, extend the current run; otherwise, reset the run to 1. Add the run length to a running total, since each valid subarray ending at the current position contributes to the count.

Pro tip: Clarify that single-element subarrays are always valid, and mention that the solution runs in O(n) time and O(1) space, which is optimal. Also, briefly discuss how you would test edge cases like empty arrays or arrays with all even/odd elements.

1. Understand the problem and define alternating condition

Confirm that a sawtooth subarray requires adjacent elements to have different parity (one even, one odd). Single-element subarrays are trivially valid.

2. Identify the linear scan approach

Recognize that the property is local: whether a subarray is sawtooth depends only on adjacent pairs. This allows a single pass through the array.

3. Track current run length and total count

Initialize current_run = 1 and total = 0. For each element from index 1 to n-1, if it alternates with the previous element, increment current_run; else reset current_run to 1. Add current_run to total at each step.

4. Handle edge cases and verify with examples

Consider empty array (return 0), single element (return 1), and arrays with no alternations. Walk through a small example to confirm the logic.

5. Analyze time and space complexity

State that the algorithm runs in O(n) time and O(1) extra space, which is optimal since every element must be examined at least once.

Key Points to Mention

  • Parity check: (a[i] % 2) != (a[i-1] % 2) or (a[i] + a[i-1]) % 2 == 1
  • Dynamic programming or running sum approach: dp[i] = dp[i-1] + 1 if alternating, else 1
  • Total count is sum of dp[i] for all i, where dp[i] is the number of valid subarrays ending at i
  • Single-element subarrays are always valid, so dp[i] starts at 1
  • Time complexity O(n) and space complexity O(1) with optimized approach
  • Edge cases: empty array, all same parity, strictly alternating array

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