If the total size of the array was even, then we know that the result would be the average of the middle two numbers (where k = totalLength/2, k & k + 1).
Should it be k - 1, k? For example, if I have [1,2,3,4]. totalLength = 4, and k=2. But the actual indices are 1 and 2, not 2 and 3.
Update: ok, the op is using 1 based array.