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.