Power Update After K-th Largest Insertion
Updated
Problem statement
You are given an integer array nums, an initial integer p, and a list of queries. Each query is a pair [value, k].
Process the queries in order. For each query:
- Insert
valueinto the multiset of stored numbers. - Let
xbe thek-th largest stored number. Equal values occupy separate ranks. - Update
ptop^x mod (10^9 + 7). - Append the updated
pto the answer.
Return the answer array after every query has been processed.
Function
powerAfterInsertions(nums: int[], p: int, queries: int[][]) → int[]Examples
Example 1
nums = [5,1,3]p = 2queries = [[4,2],[10,1]]return = [16,511620083]After inserting 4, the second-largest value is 4, so p = 2^4 = 16. After inserting 10, the largest value is 10, so p = 16^10 mod (10^9 + 7) = 511620083.
Example 2
nums = [2]p = 3queries = [[2,2],[1,3]]return = [9,9]Duplicates take separate ranks. After the first insertion, the second-largest value is 2 and p becomes 9. After inserting 1, the third-largest value is 1, so p remains 9.
Constraints
1 <= nums.length <= 10^5.1 <= queries.length <= 10^5.1 <= nums[i] <= 10^9.- Each query is
[value, k]with1 <= value <= 10^9. - For every query,
1 <= kandkdoes not exceed the number of stored values after the insertion. 0 <= p < 10^9 + 7.
More Google Online Assessment questions
- Minimum Operations to Make a SubsequenceOA · Seen Nov 2026
- Book Reading EveningsOA · Seen Nov 2026
- Count Score CategoriesOA · Seen Nov 2026
- Minimum Cars for Rental RequestsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Shortest Path in a Binary MatrixOA · Seen Nov 2026
- Robot Assembly Line ConflictsOA · Seen Oct 2026
- Assign LockerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Biggest Number From DigitsOA · Seen Oct 2026
- Consolidate On-Call RotationsOA · PHONE SCREEN · Seen Oct 2026
- Decreasing SubsequencesOA · Seen Sep 2026
Similar questions at other companies
- Maximize Shipment Order by Sorting One WindowAmazon · OA
- Delete and Freeze GameRubrik · OARubrik interview questions
- Count Pairs with K Divisible Values in the IntervalChubb · OAChubb interview questions
- Most Items Within Budget from a Start IndexHudson River Trading · OAHudson River Trading interview questions
- Backpropagation Through Sort and MedianOpenAI · OAOpenAI interview questions
- Capping Portfolio WeightsCapstone Investment Advisors · OA
- Maximum Three-Server Difficulty ScoreVisa · OAVisa interview questions
- Linear InterpolatorTwo Sigma · OATwo Sigma interview questions
- Sum of Pipeline Response TimesBloomberg LP · OABloomberg LP interview questions
- Product of Subset MaximaArcesium · OAArcesium interview questions