Skip to main content
All Questions

Maximize total gain over exactly k operations on a decaying array.

Unlock detailed company stats for this questionUpgrade

You are given an array A of size n and an integer k. You must perform exactly k operations. In the t-th operation (t starts at 1 and goes up to k), you must choose an index i and do the following:

  • Gain: add the current value of A[i] to your total gain.
  • Consume: the value at the chosen index A[i] is immediately set to 0.
  • Decay: every other element A[j] decays by the current step t multiplied by its absolute distance from the chosen index i. Elements cannot decay below 0. For all j != i: A[j] = max(0, A[j] - t * |i - j|).

Find the maximum possible gain after exactly k operations.

Community answers

No answers contributed by the community yet.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.