Find a subsequence with fastest time for specific distance I have two arrays.

seconds = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, ..., 2680]

totalMeters =  [0, 3.2, 7.1, 10.6, 14.1, 17.9, 21.5, 24.2, 27.8, 32.5, 36.9, ..., 5000]


The totalMeters array is the total meters that I have run at this specific point of time. The sampling is 2 seconds. 

I would like to find where in the array is the fastest 100 meters I have run, as well as its time.
You cannot generally get time for exactly $100$ meters with this data. The better approach would be to search for the longest run within some multiple of $2$ seconds.

Find the longest distance run in $2\cdot k$ seconds:  


Set desired k.
Set i = 0 and j = k-1.
Set currentSum = maxSum = totalMeters[j].
While j &lt; totalMeters.length - 1 do


i++; j++;
currentSum = totalMeters[j] - totalMeters[i]
if currentSum &gt; maxSum then maxSum = currentSum



This should also give you an idea how to build other similar algorithms for this problem, if you don't change your approach.