Ridgeline interview question

A leet code medium problem on arrays.