Implement two array-cost minimization algorithms | Amazon Interview Question