Given a list of elements, the task is to write a Python program to get all ranges of K greater than N.
Input : [2, 6, 6, 6, 6, 5, 4, 6, 6, 8, 4, 6, 6, 6, 2, 6], K = 6, N = 3
Output : [(1, 4), (11, 13)]
Explanation : 6 is consecutive from index 1 to 4, hence 1-4 in result. 7-8 also has 6, but its less than 3 size range, hence not included in result.
Input : [2, 1, 1, 1, 1, 5, 4, 1, 1], K = 1, N = 3
Output : [(1, 4)]
Explanation : 1 is consecutive from index 1 to 4, hence 1-4 in result. 7-8 also has 1, but its less than 3 size range, hence not included in result.
In this, each occurrence of K is traced and a nested loop is employed to get the size of the range. If the range size is greater than N, the range is recorded in the result.
The original list is : [2, 6, 6, 6, 6, 5, 4, 6, 6, 8, 4, 6, 6, 6, 2, 6]
The extracted ranges : [(1, 4), (11, 13)]
In this, all the pairs of ending and starting of K are extracted with previous and next element respectively. The pairs index are then checked to have required ranges in between to add to the result in the list.
The original list is : [2, 6, 6, 6, 6, 5, 4, 6, 6, 8, 4, 6, 6, 6, 2, 6]
The extracted ranges : [(1, 4), (11, 13)]
Time complexity: O(n*n), where n is the length of the test_list. The enumerate() + zip() + list slicing + list comprehension takes O(n*n) time
Auxiliary Space: O(n), extra space of size n is required