Help Needed — Modified version of [Maximum sum of size K in Circular Subarray]

Правка en1, от abhi55, 2024-07-17 23:13:51

Given an Array of integers where each element represent 1 to array[i] days. find maximum possible k consecutive days in circular array.

Example: arr = [7, 4, 6, 3, 5] k = 8 output = 33

explanation: we can choose last day of arr4 which is 5 and all of 7 days of arr1. So, it will look like sum(5,1,2,3,4,5,6,7) = 33.

My thoughts: this look like classical sliding window problem to find max subarray of size k but converting original array to actual days array([1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 1, 2, 3, 4, 5, 6, 1, 2, 3, 1, 2, 3, 4, 5]) like this will not be optimal and what if size of k is far greater than length of array?.

Need help if anybody have some pointers how to solve this question.

Теги sliding window, greedy

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский abhi55 2024-07-17 23:13:51 816 Initial revision (published)