Capital One logo

Capital One Hard Interview Questions

6 hard-level practice questions for Capital One technical interviews

Capital One software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.

Software Engineer Backend Engineer Frontend Engineer Full Stack Engineer Mobile Engineer Data Engineer Data Scientist ML Engineer DevOps Engineer DevOps Engineer Product Manager SRE Security Engineer Engineering Manager Data Analyst UX/UI Designer QA Engineer
coding Hard Verified Question #1

1. [CodeSignal] Battery Rotation Scheduler


Category: Array coding problem
A remote system uses a circular array of backup generators to sustain a critical task. Each generator can power the system for a fixed number of...
Input: Array
Output: Integer
Want to practise this one?
Create a free account to open the full question and practise Capital One questions with AI.
Sign up free
coding Hard Verified Question #2

2. [CodeSignal] Grid Arithmetic Path


Category: Matrix coding problem
You are given a grid where each cell contains either a single digit ('0' to '9') or an arithmetic operator ('+' or '-'). Starting from any cell, you...
Input: Matrix (2D array)
Output: Integer
coding Hard Verified Question #3

3. Text Layout Formatter


Category: Graph coding problem
You are formatting a document page. Given paragraphs (a 2D array of words), aligns (alignment per paragraph), and width (maximum characters per...
Input: Graph (nodes and edges)
Output: Computed result
coding Hard Verified Question #4

4. [CodeSignal] Round-Robin Package Dispatcher


Category: Trie-based coding problem
A logistics platform assigns packages to processing stations in round-robin order. You are given stationCapacity (max packages each station can...
Input: Given input
Output: Integer
coding Hard stack queue #1

1. [AI Enabled Coding] Virtual Card Authorization Rules


Scenario


Capital One's Eno virtual cards help customers pay online without exposing their physical card number; an authorization service must evaluate purchases against card restrictions and shared-account controls. Build a simplified, in-memory authorization evaluator with an AI assistant, explaining and testing the generated code as you work. This exercise adapts the reported Capital One virtual-credit-card validation case; the specific rules and limits below are exercise assumptions, not actual Capital One policies.

Part 1 — Card-level authorization


  • Card configuration records have string fields card_id, account_id, and merchant_id. Each card is locked to its configured merchant.

  • Transaction records have string fields id, card_id, merchant_id, amount, and timestamp. Amounts are dollar strings with exactly two decimal places; timestamps are Unix seconds encoded as strings.

  • Rule MERCHANT_LOCK fails when the transaction's merchant differs from its card's configured merchant.

  • Rule MAX_TRANSACTION fails when the amount is strictly greater than 500.00. Exactly 500.00 is allowed.

  • Evaluate every applicable rule, even after another rule fails. Approve only when no rule fails; otherwise decline. Return failed rule IDs in ascending lexicographic order, and preserve transaction input order.

  • Use exact integer-cent arithmetic. Build an extensible rule abstraction rather than placing all conditions in one monolithic function.


Function signature: evaluate_part1(cards: list[dict[str, str]], transactions: list[dict[str, str]])
The return type is up to the candidate. The examples use a list of decision objects with id, status, and reasons; your representation must convey the same information.

Example 1:


Input:
{
  "cards": [
    {"card_id": "c1", "account_id": "a1", "merchant_id": "shop-a"},
    {"card_id": "c2", "account_id": "a1", "merchant_id": "shop-b"}
  ],
  "transactions": [
    {"id": "t1", "card_id": "c1", "merchant_id": "shop-a", "amount": "200.00", "timestamp": "0"},
    {"id": "t2", "card_id": "c1", "merchant_id": "shop-b", "amount": "10.00", "timestamp": "1"},
    {"id": "t3", "card_id": "c2", "merchant_id": "shop-b", "amount": "500.00", "timestamp": "2"},
    {"id": "t4", "card_id": "c2", "merchant_id": "shop-b", "amount": "500.01", "timestamp": "3"},
    {"id": "t5", "card_id": "c1", "merchant_id": "shop-b", "amount": "600.00", "timestamp": "4"}
  ]
}

Output:
[
  {"id": "t1", "status": "APPROVED", "reasons": []},
  {"id": "t2", "status": "DECLINED", "reasons": ["MERCHANT_LOCK"]},
  {"id": "t3", "status": "APPROVED", "reasons": []},
  {"id": "t4", "status": "DECLINED", "reasons": ["MAX_TRANSACTION"]},
  {"id": "t5", "status": "DECLINED", "reasons": ["MAX_TRANSACTION", "MERCHANT_LOCK"]}
]

Explanation: t1 and t3 satisfy both rules, including the inclusive 500.00 boundary. t2 uses the wrong merchant, t4 exceeds the amount limit by 0.01, and t5 fails both rules.

Part 2 — Configurable overlapping spending windows


Risk teams now supply additional policy records. Each policy has string fields rule_id, scope, entity_id, window_seconds, and limit. Its scope is either card, matching a card_id, or account, matching the card's account_id. Multiple policies with different windows and limits may target the same entity.
  • Retain every Part 1 rule. A transaction must pass those rules and every matching window policy.

  • For a policy with window length W, at transaction time t, let S be the sum of previously approved, matching transactions with timestamps in the interval (t - W, t]. Fail that policy exactly when S + current_amount > limit.

  • Process equal timestamps in input order: an earlier approved transaction at the same timestamp counts toward a later transaction.

  • Evaluate all matching policies against previously approved activity, even if a Part 1 rule fails. Include every failed policy's rule_id in the same sorted reasons list.

  • Commit a transaction to all matching policies only if every rule passes. A declined transaction consumes no limit, and previously declined transactions are never reconsidered.

  • Return decisions plus a snapshot of every policy's approved total at the final transaction timestamp. Apply the same window boundary to snapshots, and sort snapshots by rule_id. Render snapshot totals with exactly two decimal places.

  • The approach must support future additional rule classes and additional policy records without rewriting Part 1. Do not scan every configured policy or all prior transactions for every authorization.


Before implementing, discuss how your return type changes to include policy snapshots.
Function signature: evaluate_part2(cards: list[dict[str, str]], transactions: list[dict[str, str]], policies: list[dict[str, str]])

Example 2:


Input:
{
  "cards": [
    {"card_id": "c1", "account_id": "a1", "merchant_id": "shop-a"},
    {"card_id": "c2", "account_id": "a1", "merchant_id": "shop-b"}
  ],
  "policies": [
    {"rule_id": "CARD_60", "scope": "card", "entity_id": "c1", "window_seconds": "60", "limit": "300.00"},
    {"rule_id": "ACCOUNT_120", "scope": "account", "entity_id": "a1", "window_seconds": "120", "limit": "450.00"}
  ],
  "transactions": [
    {"id": "p1", "card_id": "c1", "merchant_id": "shop-a", "amount": "200.00", "timestamp": "0"},
    {"id": "p2", "card_id": "c2", "merchant_id": "shop-b", "amount": "200.00", "timestamp": "10"},
    {"id": "p3", "card_id": "c1", "merchant_id": "shop-a", "amount": "110.00", "timestamp": "20"},
    {"id": "p4", "card_id": "c1", "merchant_id": "shop-a", "amount": "50.00", "timestamp": "30"},
    {"id": "p5", "card_id": "c1", "merchant_id": "shop-a", "amount": "100.00", "timestamp": "60"}
  ]
}

Output:
{
  "decisions": [
    {"id": "p1", "status": "APPROVED", "reasons": []},
    {"id": "p2", "status": "APPROVED", "reasons": []},
    {"id": "p3", "status": "DECLINED", "reasons": ["ACCOUNT_120", "CARD_60"]},
    {"id": "p4", "status": "APPROVED", "reasons": []},
    {"id": "p5", "status": "DECLINED", "reasons": ["ACCOUNT_120"]}
  ],
  "policy_totals": [
    {"rule_id": "ACCOUNT_120", "approved_total": "450.00"},
    {"rule_id": "CARD_60", "approved_total": "50.00"}
  ]
}

Explanation: After p1 and p2, the account total is 400.00 and c1's total is 200.00. p3 would produce account usage 510.00 > 450.00 and card usage 310.00 > 300.00, so neither policy records it. p4 produces account usage 450.00 and card usage 250.00, so it passes. At time 60, p1 is exactly on the card window's excluded boundary; p5 would produce card usage 50.00 + 100.00 = 150.00, but account usage 450.00 + 100.00 = 550.00, so it fails only ACCOUNT_120. Final totals are therefore 450.00 and 50.00.

Example 3:


Input:
{
  "cards": [
    {"card_id": "c1", "account_id": "a1", "merchant_id": "shop-a"},
    {"card_id": "c2", "account_id": "a1", "merchant_id": "shop-b"}
  ],
  "policies": [
    {"rule_id": "CARD_60", "scope": "card", "entity_id": "c1", "window_seconds": "60", "limit": "300.00"},
    {"rule_id": "ACCOUNT_120", "scope": "account", "entity_id": "a1", "window_seconds": "120", "limit": "450.00"}
  ],
  "transactions": [
    {"id": "e1", "card_id": "c1", "merchant_id": "shop-a", "amount": "300.00", "timestamp": "0"},
    {"id": "e2", "card_id": "c2", "merchant_id": "shop-b", "amount": "150.00", "timestamp": "0"},
    {"id": "e3", "card_id": "c1", "merchant_id": "shop-b", "amount": "600.00", "timestamp": "1"},
    {"id": "e4", "card_id": "c1", "merchant_id": "shop-a", "amount": "1.00", "timestamp": "60"},
    {"id": "e5", "card_id": "c1", "merchant_id": "shop-a", "amount": "300.00", "timestamp": "120"},
    {"id": "e6", "card_id": "c2", "merchant_id": "shop-b", "amount": "150.00", "timestamp": "120"}
  ]
}

Output:
{
  "decisions": [
    {"id": "e1", "status": "APPROVED", "reasons": []},
    {"id": "e2", "status": "APPROVED", "reasons": []},
    {"id": "e3", "status": "DECLINED", "reasons": ["ACCOUNT_120", "CARD_60", "MAX_TRANSACTION", "MERCHANT_LOCK"]},
    {"id": "e4", "status": "DECLINED", "reasons": ["ACCOUNT_120"]},
    {"id": "e5", "status": "APPROVED", "reasons": []},
    {"id": "e6", "status": "APPROVED", "reasons": []}
  ],
  "policy_totals": [
    {"rule_id": "ACCOUNT_120", "approved_total": "450.00"},
    {"rule_id": "CARD_60", "approved_total": "300.00"}
  ]
}

Explanation: e1 reaches the card cap exactly; e2, processed next at the same timestamp, reaches the shared account cap exactly. e3 fails four rules: wrong merchant, 600.00 > 500.00, proposed card total 300.00 + 600.00 = 900.00, and proposed account total 450.00 + 600.00 = 1050.00. At time 60, the card total has expired, but e4 still fails because the account would reach 451.00. At time 120, both time-zero purchases leave the account window; e5 and e6 then rebuild its total to 300.00 + 150.00 = 450.00. Only e5 belongs to c1, leaving its total at 300.00.

Notes:


  • Each invocation starts with empty activity. Inputs are valid: IDs are unique within their record type, every transaction references a configured card, policies reference configured entities, and policy IDs do not collide with built-in rule IDs. Transactions arrive in nondecreasing timestamp order; configurations do not change during a call.

  • There are 1–200,000 transactions, 1–50,000 cards, and 0–10,000 policies, with at most eight policies for any (scope, entity_id) pair. Window lengths are 1–86,400 seconds; timestamps are nonnegative; amounts and limits range from 0.01 to 1000000000.00.

  • This is a single-threaded authorization simulation: no refunds, retries, currency conversion, or external persistence. Explain amortized runtime and memory usage, including overlapping-window state.
Want to practise this one?
Create a free account to open the full question and practise Capital One questions with AI.
Sign up free
coding Hard heap #2

2. [Heap] — Implement a bank with efficient most-active-account queries


Background
Capital One interview reports describe implementing a banking system with deposits, withdrawals, transfers, and a ranking of the most-active accounts. This exercise models those account operations and adds performance requirements for maintaining activity rankings as transactions arrive; it is not a description of Capital One's production implementation.
Problem statement
Implement an in-memory Bank that maintains account balances in integer cents and supports ranking accounts by their number of successful operations.
Each account has a unique string ID, an initial balance of zero, and an initial activity count of zero. Apply these rules:
  • Creating an existing account fails. Account creation does not increase activity.

  • A deposit succeeds only when the account exists and the amount is positive.

  • A withdrawal additionally requires sufficient funds.

  • A transfer succeeds only when both accounts exist, the IDs differ, the amount is positive, and the source has sufficient funds. A successful transfer changes both balances atomically.

  • Each successful deposit or withdrawal increases that account's activity count by one. Each successful transfer increases both participating accounts' counts by one, regardless of the transferred amount.

  • Failed operations change neither balances nor activity counts.

  • A balance lookup does not increase activity and returns None for an unknown account.

  • top_active(k) returns up to k account IDs, ordered by decreasing activity count, breaking ties by lexicographically increasing account ID. Accounts with zero activity are included. Return an empty list when k <= 0.


Let n be the current number of accounts and r = min(max(k, 0), n). Support account creation and each transaction in O(log(n + 1)) time, balance lookups in expected O(1) time, and ranking queries in O(r log(r + 1)) time. Maintain O(n) persistent storage, independent of transaction history, with at most O(r) temporary storage per ranking query. Do not sort all accounts on every query or retain stale ranking entries indefinitely. Hash-table accesses may be treated as expected O(1).
Function or class signature
  • Bank() — construct an empty bank.

  • create_account(account_id: str) -> bool

  • deposit(account_id: str, amount: int) -> bool

  • withdraw(account_id: str, amount: int) -> bool

  • transfer(source_id: str, destination_id: str, amount: int) -> bool

  • get_balance(account_id: str) -> int | None

  • top_active(k: int) -> list[str]


Example 1:
Input
{
  "operations": [
    ["create_account", "A"],
    ["create_account", "B"],
    ["create_account", "C"],
    ["deposit", "A", 1000],
    ["transfer", "A", "B", 300],
    ["withdraw", "B", 100],
    ["top_active", 3],
    ["get_balance", "A"],
    ["get_balance", "B"]
  ]
}
Output
[true, true, true, true, true, true, ["A", "B", "C"], 700, 200]
Explanation
A has two successful operations: its deposit and the transfer. B also has two: the transfer and its withdrawal. A ranks before B by account ID, while C has zero activity. The balances are 1000 - 300 = 700 and 300 - 100 = 200 cents.
Example 2:
Input
{
  "operations": [
    ["create_account", "B"],
    ["create_account", "A"],
    ["create_account", "A"],
    ["deposit", "B", 500],
    ["transfer", "B", "B", 100],
    ["transfer", "B", "A", 600],
    ["withdraw", "A", 1],
    ["deposit", "A", 0],
    ["top_active", 10],
    ["transfer", "B", "A", 500],
    ["withdraw", "A", 500],
    ["top_active", 2],
    ["get_balance", "B"],
    ["get_balance", "missing"],
    ["top_active", 0]
  ]
}
Output
[true, true, false, true, false, false, false, false, ["B", "A"], true, true, ["A", "B"], 0, null, []]
Explanation
Before the first ranking query, only B's deposit succeeds, giving activity counts B = 1 and A = 0. The valid transfer then gives B = 2 and A = 1; A's withdrawal raises A to 2. Their final counts tie, so A comes first. Both balances finish at zero, and every rejected operation leaves the state unchanged.
Constraints:
  • At most 200000 method calls and 200000 distinct accounts.

  • Account IDs contain 1 to 32 uppercase English letters or digits; compare them using ordinary lexicographic string order.

  • Amounts are integer cents with -10^12 <= amount <= 10^12; nonpositive amounts must be rejected.

  • -200000 <= k <= 200000.

  • Calls are single-threaded; all state fits in memory.

  • Balances fit in signed 64-bit integers. Fixed-length account IDs may be treated as constant-size keys for complexity analysis.


Follow-up:
Now support undo(transaction_id), which reverses a previously successful transaction exactly once, including its activity increments. Reject an undo if it would make any balance negative. How would you modify the ranking structure to support both increasing and decreasing activity in O(log(n + 1)) time, and what additional transaction history would you need?

Start practicing Capital One questions

Sign up for free to access walkthroughs, AI-generated questions, and more.

Get Started Free