MoveWORK interview question

Leetcode question that was medium