Dynamic Pair Sum Queries
Updated
Problem statement
The array that gets updated is the first parameter, a.
You are given two integer arrays a and b and a sequence of queries. Process the queries in order.
- A query
[0, i, x]addsxtoa[i]. - A query
[1, x]asks for the number of index pairs(i, j)such that the current values satisfya[i] + b[j] = x.
Return the answers to all type-1 queries in their original order.
Function
processPairSumQueries(a: int[], b: int[], queries: int[][]) → long[]Examples
Example 1
a = [1,4]b = [1,2,3]queries = [[1,5],[0,0,2],[1,5]]return = [1,2]Before the update, only a[1] + b[0] = 4 + 1 = 5, so the first answer is 1. The update changes a[0] from 1 to 3. Then both 3 + 2 and 4 + 1 equal 5, so the second answer is 2.
Constraints
a,b, andqueriesare non-empty.- Every type-
0query has the form[0, i, x]with0 <= i < a.length. - Every type-
1query has the form[1, x]. - Array
bis never modified.
More ZipRecruiter Online Assessment questions
- Four-Level Banking System with Scheduled PaymentsOA · Seen Oct 2026
- Count Three-Digit Numbers with Distinct DigitsOA · Seen Oct 2024
- Longest Frequency-Bounded SubarrayOA · Seen Oct 2024
- Minimum Changes to Draw a YOA · Seen Oct 2024
- Apply Binary State OperationsOA · Seen Sep 2024
- Simulate Orchard Rot SpreadOA · Seen Sep 2024
- Compare Odd- and Even-Index SumsOA · Seen Sep 2024
- Coordinate Removals with Column GravityOA · Seen Sep 2024
- Lexicographically Smallest End ReversalOA · Seen Sep 2024
- Recursively Expanded Shell Command CountsOA · Seen Sep 2024
Similar questions at other companies
- Bank Accounts with Balance HistoryMeta · OAMeta interview questions
- Top K Frequent ElementsAmazon · OA · PHONE SCREEN
- Count Overlapping Square PairsRamp · OARamp interview questions
- Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
- Count Belt Sections With K Fruit Pairs (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
- Count Suffix Word PairsTikTok · OATikTok interview questions
- Count Servers With No Requests in a Time WindowIBM · OAIBM interview questions
- Find Valid SET Card TriplesSnowflake · OA · PHONE SCREENSnowflake interview questions
- Maximum Escape Game ScoreMicrosoft · OAMicrosoft interview questions
- Stacked Item and Category DiscountsPalantir · OAPalantir interview questions