Sum of the Last K Elements
Numbers arrive one at a time. After each arrival print the sum of the most recent k numbers (or of all numbers so far if fewer than k have arrived). Use a ring buffer of size k.
Constraints
1 <= k <= n <= 10^5 |a[i]| <= 10^4
Discussion
No discussions yet.
Shalyam Support
Hi! Ask us anything — we'll reply on WhatsApp or Telegram within 24 hours.