Pragmatic Play Interview Question

Task from leetcode (easy level)