Amazon Interview Question

Minimum sum of distances coding question