Grid Dynamics interview question

Some technical tasks from leetcode