Minimize reduction cost and validate equal-sum pairs | MathWorks Interview Question