PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Capital One

Solve OA tasks on string, grid path, subarrays

Last updated: Mar 29, 2026

Quick Overview

This multi-part question evaluates string manipulation, constrained grid-path optimization with sequential expression evaluation, and counting of parity-alternating subarrays, measuring competencies in algorithm design, dynamic programming or combinatorial path reasoning, and linear-time array techniques.

  • easy
  • Capital One
  • Coding & Algorithms
  • Machine Learning Engineer

Solve OA tasks on string, grid path, subarrays

Company: Capital One

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Take-home Project

You are given three independent coding tasks. ## Task 1: Reverse the middle if ends are vowels Given a string `s` (ASCII letters), if **both** the first and last characters are vowels (`a,e,i,o,u` case-insensitive), return a new string where: - the first and last characters stay in place, and - the substring strictly between them is reversed. Otherwise, return `s` unchanged. **Examples** - `"apple"` → first=`a` (vowel), last=`e` (vowel) ⇒ reverse middle `"ppl"` → `"alppe"` - `"code"` → first=`c` not vowel ⇒ `"code"` **Edge cases** - If `len(s) <= 2`, there is no “middle”; return `s`. --- ## Task 2: Maximize value along a constrained grid path You are given an `m x n` grid of characters. Each cell contains either: - a digit `'0'..'9'`, or - an operator `'+'` or `'-'`. You start at the **top-left** cell `(0,0)` and must reach the **bottom-right** cell `(m-1,n-1)` by moving only: - **right**, or - **down**. As you traverse cells, you concatenate their characters to form an arithmetic expression, which is evaluated **left-to-right** (i.e., no operator precedence beyond sequential evaluation). **Validity assumption:** Any path considered must form a valid expression of the form `digit (op digit)*` (alternating digit/operator), and it must start and end with a digit. **Direction-change constraint:** Along the path, you are allowed to change direction **at most once** (i.e., the move sequence is either all rights then all downs, or all downs then all rights). **Goal:** Return the **maximum** value achievable among all valid paths satisfying the movement constraint. --- ## Task 3: Count alternating odd/even subarrays Given an integer array `nums`, count how many **contiguous subarrays** have strictly alternating parity (odd/even/odd/even... or even/odd/even/odd...). A subarray of length 1 always counts. **Example** - `nums = [1, 2, 4]` - Alternating subarrays: `[1]`, `[2]`, `[4]`, `[1,2]`, but `[2,4]` is not alternating (even, even), and `[1,2,4]` is not alternating. - Answer = `4` **Performance requirement:** Design an algorithm faster than brute force (e.g., `O(n)`).

Quick Answer: This multi-part question evaluates string manipulation, constrained grid-path optimization with sequential expression evaluation, and counting of parity-alternating subarrays, measuring competencies in algorithm design, dynamic programming or combinatorial path reasoning, and linear-time array techniques.

Related Interview Questions

  • Solve Four Coding Assessment Tasks - Capital One (medium)
  • Write SQL using joins and window functions - Capital One (medium)
  • Review Preprocessing Code and Tests - Capital One (easy)
  • Remove nodes with a given value - Capital One (medium)
  • Solve multiple algorithmic interview questions - Capital One (hard)
Capital One logo
Capital One
Jan 21, 2026, 12:00 AM
Machine Learning Engineer
Take-home Project
Coding & Algorithms
7
0
Loading...

You are given three independent coding tasks.

Task 1: Reverse the middle if ends are vowels

Given a string s (ASCII letters), if both the first and last characters are vowels (a,e,i,o,u case-insensitive), return a new string where:

  • the first and last characters stay in place, and
  • the substring strictly between them is reversed.

Otherwise, return s unchanged.

Examples

  • "apple" → first= a (vowel), last= e (vowel) ⇒ reverse middle "ppl" → "alppe"
  • "code" → first= c not vowel ⇒ "code"

Edge cases

  • If len(s) <= 2 , there is no “middle”; return s .

Task 2: Maximize value along a constrained grid path

You are given an m x n grid of characters. Each cell contains either:

  • a digit '0'..'9' , or
  • an operator '+' or '-' .

You start at the top-left cell (0,0) and must reach the bottom-right cell (m-1,n-1) by moving only:

  • right , or
  • down .

As you traverse cells, you concatenate their characters to form an arithmetic expression, which is evaluated left-to-right (i.e., no operator precedence beyond sequential evaluation).

Validity assumption: Any path considered must form a valid expression of the form digit (op digit)* (alternating digit/operator), and it must start and end with a digit.

Direction-change constraint: Along the path, you are allowed to change direction at most once (i.e., the move sequence is either all rights then all downs, or all downs then all rights).

Goal: Return the maximum value achievable among all valid paths satisfying the movement constraint.

Task 3: Count alternating odd/even subarrays

Given an integer array nums, count how many contiguous subarrays have strictly alternating parity (odd/even/odd/even... or even/odd/even/odd...).

A subarray of length 1 always counts.

Example

  • nums = [1, 2, 4]
    • Alternating subarrays: [1] , [2] , [4] , [1,2] , but [2,4] is not alternating (even, even), and [1,2,4] is not alternating.
    • Answer = 4

Performance requirement: Design an algorithm faster than brute force (e.g., O(n)).

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Capital One•More Machine Learning Engineer•Capital One Machine Learning Engineer•Capital One Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.