Goldman Sachs Interview Question

2D dp. Calculate minimum distance