This is a verified interview question from Google. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Recursive Cache Amplification Maximizer" covers key patterns like DP.
"Google Big Code In a distributed computing system, you are managing N memory cache blocks, each with a frequency level represented in an array A, along with an integer K. Cache blocks with the same frequency level are grouped together and can trigger recursive amplification cycles. ### The Global Frequency Pool There exists exactly one shared, mutable global pool that tracks the count of cache blocks at each frequency level. It is initialized from array A. All operations read from blocks at each frequency level. It is initialized from array A. All operations read from this single pool. There are no snapshots, resets, or independent copies at any point during execution. All frequency counts in the pool fit within 64-bit signed integers throughout execution. ### Amplification Operation An amplification operation may be performed on frequency level X if the pool currently contains at least K cache blocks of level X. The operation proceeds as follows: 1. Compute groups = (count[X] / K) 2. Add X × groups to the running score for this amplification chain ### Chain Execution Model - Each distinct frequency level from the initial input is considered exactly once as a starting point. Only frequency levels present in the original input array A are eligible to start chains, regardless of how many times a value appears in A. Newly created frequency levels (X^2, X^4, ...) are used solely for continuing existing chains and are never treated as new starting points. - The pool is actively modified during iteration — newly inserted frequency levels during chain execution may or may not be visited as starting points, depending on hash table implementation behavior. Visitation of newly inserted keys is not hash table implementation behavior. ### Overflow and Chain Termination - Frequency levels grow as X → X^2 → X^4 → .... This is exponential growth. A chain may traverse very few steps before values become too large to represent. - If computing X^2 would overflow a 64-bit signed integer, the chain terminates immediately at that step. Specifically, the chain stops if - No explicit cap on cache block count exists. Because blocks are never evicted, ### Starting Eligibility A chain is attempted for frequency level X only if X was present in the original input array A and count[X] ≥ K at the moment X is processed. - If count[X] < K at that moment, the chain is skipped entirely — no points are scored for it. - If no distinct frequency level from the original input satisfies count[X] ≥ K at the time of processing, the result is 0. ### Function Description Complete the solve function. It receives N (the number of crystals), K (the number of crystals needed for transmutation), and A (an array of N integers representing crystal energy levels). The function uses hash table frequency tracking combined with greedy simulation to find the maximum score achievable through optimal transmutation chains. It returns the maximum total score as a long long. ### Function Parameters N: integer — the number of crystals K: integer — the number of crystals required for each transmutation A: array of N long long integers — the energy levels of the crystals"
Join thousands of developers practicing for Google.