PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Capital One

Support updates and count target-sum pairs

Last updated: Mar 29, 2026

Quick Overview

This question evaluates data structures and algorithmic skills for dynamic pair counting, focusing on frequency management, efficient update handling, and query-time computation in a two-sum variant.

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

Support updates and count target-sum pairs

Company: Capital One

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Take-home Project

You are given two integer arrays: - `A` (fixed / primary) - `B` (modifiable / secondary) You must process a sequence of operations of two types: 1. **Update**: set `B[index] = value`. 2. **Query**: given an integer `target`, return the **number of pairs** `(i, j)` such that `A[i] + B[j] == target`. Pairs are counted with multiplicity: if `A` contains duplicates or `B` contains duplicates, each index combination counts as a distinct pair. ### Input - Arrays `A` and `B` - A list of operations, each operation is either: - `("update", index, value)` - `("count", target)` ### Output For each `("count", target)` operation, output an integer: the number of valid pairs. ### Example - `A = [1, 2, 2]` - `B = [3, 2]` - Query `target = 4` - Valid pairs are `(1,3)`, `(2,2)` using the first `2` in `A`, and `(2,2)` using the second `2` in `A` → total `3`. ### Constraints (assume typical interview constraints) - `1 <= len(A), len(B) <= 10^5` - Number of operations up to `10^5` - Values can be negative and up to typical 32-bit integer range.

Quick Answer: This question evaluates data structures and algorithmic skills for dynamic pair counting, focusing on frequency management, efficient update handling, and query-time computation in a two-sum variant.

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 6, 2026, 12:00 AM
Machine Learning Engineer
Take-home Project
Coding & Algorithms
4
0
Loading...

You are given two integer arrays:

  • A (fixed / primary)
  • B (modifiable / secondary)

You must process a sequence of operations of two types:

  1. Update : set B[index] = value .
  2. Query : given an integer target , return the number of pairs (i, j) such that A[i] + B[j] == target .

Pairs are counted with multiplicity: if A contains duplicates or B contains duplicates, each index combination counts as a distinct pair.

Input

  • Arrays A and B
  • A list of operations, each operation is either:
    • ("update", index, value)
    • ("count", target)

Output

For each ("count", target) operation, output an integer: the number of valid pairs.

Example

  • A = [1, 2, 2]
  • B = [3, 2]
  • Query target = 4
    • Valid pairs are (1,3) , (2,2) using the first 2 in A , and (2,2) using the second 2 in A → total 3 .

Constraints (assume typical interview constraints)

  • 1 <= len(A), len(B) <= 10^5
  • Number of operations up to 10^5
  • Values can be negative and up to typical 32-bit integer range.

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.