Wix interview question

snake solver question in leetcode