Company: Agoda
Difficulty: medium
Slow and Fast Pointers You are given an array arr and must scan it using two pointers, P1 and P2 , together with a candidate step length called segSize . Begin a trial by choosing a value for segSize , then set P1 = 0 and P2 = 1 . Check whether arr[P1] is greater than or equal to every element in the block of up to segSize entries that begins at arr[P2] (the block ends early if it would otherwise run past the last index of arr ). If the check passes for the whole block, advance P1 by one, advance P2 by segSize , and evaluate the next block the same way. Continue until a block reaching the final index of arr has been checked successfully. Among all values of segSize for which the entire array can be walked through in this manner, report the smallest one, or -1 if no such value exists. Function Description Implement the function dualSpeed , which receives: 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: segSiz