Goldman Sachs interview question

2D dp. Calculate minimum distance