FastPrepPower Update After K-th Largest Insertion
Problems/Power Update After K-th Largest Insertion

Power Update After K-th Largest Insertion

Google logoGoogle● HardINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The firsthand report describes append queries, picking the kth-largest value, and repeated power updates with a modulus. It does not give input limits, and the caret notation is unclear. Here we use modular exponentiation and the usual limits for valid queries. Our version is about 94% the same as the reported question.

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:

  1. Insert value into the multiset of stored numbers.
  2. Let x be the k-th largest stored number. Equal values occupy separate ranks.
  3. Update p to p^x mod (10^9 + 7).
  4. Append the updated p to 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] with 1 <= value <= 10^9.
  • For every query, 1 <= k and k does 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

Interview reports that mention this question

  • Google OA: What It Tests (2026)
  • Google SWE Intern OA and Interviews: 42 Experiences (Part 1 of 3)

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int[] powerAfterInsertions(int[] nums, int p, int[][] queries) {
        // Write your code here.
    }
}
Checking account…