You are given two arrays of integers, a and b, and an array queries. Process every query in order.
Each query has one of the following forms:
[0, i, x]: assigna[i]the valuex.[1, x]: count the number of pairs of indicesiandjsuch thata[i] + b[j] = x.
Return an array containing the results of the queries of the form [1, x], in the same order as those queries appear.
Examples
01 · Example 1
a = [3, 4] b = [1, 2, 3] queries = [[1, 5], [0, 0, 1], [1, 5]] return = [2, 1]
For the first query [1, 5], there are two valid pairs: a[0] + b[1] = 3 + 2 = 5 and a[1] + b[0] = 4 + 1 = 5.
The query [0, 0, 1] changes a[0] to 1, so a = [1, 4].
For the final query [1, 5], only a[1] + b[0] = 4 + 1 = 5 remains valid.
02 · Example 2
a = [1, 1] b = [2, 3] queries = [[1, 3], [0, 1, 2], [1, 3], [1, 4]] return = [2, 1, 2]
Initially both values in a pair with b[0] = 2 to form 3, so the first answer is 2.
After assigning a[1] = 2, the arrays are a = [1, 2] and b = [2, 3]. There is one pair that sums to 3 and two pairs that sum to 4.
Constraints
aandbare arrays of integers.- Each update query has the form
[0, i, x]. - Each count query has the form
[1, x].
More Tiktok problems
- Check Even-Position MonotonicityOA · Seen Jun 2026
- Count Alternating Tile GroupsOA · Seen Jun 2026
- Count Even-Digit NumbersOA · Seen Jun 2026
- Inventory Discount TrackerOA · Seen Jun 2026
- Construct WDL StringOA · Seen Jun 2026
- LRU Cache with TTL ExpirationONSITE INTERVIEW · Seen May 2026
- Maximum Candies with At Most Two Types in a LineONSITE INTERVIEW · Seen May 2026
- Top-K KOLs by Total LikesONSITE INTERVIEW · Seen May 2026
public int[] solution(int[] a, int[] b, int[][] queries) {
// write your code here
}a[3, 4]
b[1, 2, 3]
queries[[1, 5], [0, 0, 1], [1, 5]]
expected[2, 1]
sign in to submit