Company: Agoda
Difficulty: medium
Slow and Fast Pointers Process an array, arr , using two pointers, P1 and P2 , and an integer, segSize . Pick an integer to test for segSize , then start with P1 = 0 and P2 = 1 . Compare the value at arr[P1] with all of the elements in a subarray. The subarray starts at arr[P2] and includes segSize elements or it reaches the end of arr . If arr[P1] is greater or equal in all cases, increment P1 by 1, increment P2 by segSize , and repeat the process. Do this until the subarray including the last element of arr has been processed. Determine the minimum value of segSize that allows the entire array to be processed. Return this minimum step value or -1 if it is not possible. Function Description Complete the function dualSpeed that takes the following parameter: arr[n] : an array of integers Constraints 1 ≤ n ≤ 5000 1 ≤ arr[i] ≤ 10 9 Example Given array: arr = [11, 9, 10, 8, 10, 9] Try: segSize = 1 P1 P2 arr[P1] Subarray Continue 0 1 11 [9] y 1 2 9 [10] n (fails because 10 > 9) Try: segSiz