arr
.m
using the formula m = arr[(len(arr) - 1) // 2]
.i
at the start of the array and j
at the end.result
to store the strongest elements.result
is less than k
:
a. Compare abs(arr[i] - m)
with abs(arr[j] - m)
.
b. If abs(arr[i] - m)
is greater, append arr[i]
to result
and increment i
.
c. Else, append arr[j]
to result
and decrement j
.result
containing the k
strongest elements.