Finding Pairs With a Certain Sum
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Implement FindSumPairs(nums1, nums2), which holds two integer arrays and supports two operations:
- add(index, val) increases nums2[index] by val.
- count(tot) returns the number of index pairs (i, j) with nums1[i] + nums2[j] == tot.
Pairs are counted by index, so equal values at different positions count separately. nums1 is short and never changes, while nums2 can be long and is updated in place.
Examples
Constraints
- 1 <= nums1.length <= 1000
- 1 <= nums2.length <= 10^5
- 1 <= nums1[i] <= 10^9, 1 <= nums2[i] <= 10^5
- 0 <= index < nums2.length, 1 <= val <= 10^5
- 1 <= tot <= 10^9
- At most 1000 calls each to `add` and `count`
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.