Given a list, the task is to write a Python Program to count a maximum number of times K occurs consecutively in each batch of size N.
Input : test_list = [4, 4, 5, 4, 4, 4, 1, 2, 3, 4, 4, 4, 4, 4, 4, 4, 5, 6, 7, 4, 4, 5, 3, 4, 4, 4, 7, 4, 4, 4, 5, 6, 3, 5, 4, 4, 4, 6, 4, 4, 1, 4, 2, 4, 4], N = 15, K = 4
Output : [6, 3, 3]
Explanation : For first batch of 15 elements, 4 occurs in consecution, 2, 3 and 6. times. Since 6 is maximum hence one of output.
Input : test_list = [4, 4, 5, 4, 4, 4, 1, 2, 3, 4, 4, 4, 4, 4, 4, 4, 5, 6, 7, 4, 4, 5, 3, 4, 4, 4, 7, 4, 4, 4], N = 15, K = 4
Output : [6, 3]
Explanation : For first batch of 15 elements, 4 occurs in consecution, 2, 3 and 6. times. Since 6 is maximum hence one of output.
In this, we get each consecution using slicing and using range to jump K elements to start grouping for each batch. The max() gets the maximum length of K consecutive group in each batch.
The original list is : [4, 4, 5, 4, 4, 4, 1, 2, 3, 4, 4, 4, 4, 4, 4, 4, 5, 6, 7, 4, 4, 5, 3, 4, 4, 4, 7, 4, 4, 4, 5, 6, 3, 5, 4, 4, 4, 6, 4, 4, 1, 4, 2, 4, 4]
Maximum consecution of K for each batch : [6, 3, 3]