Scott Logic Interview Question

A Complex leet code challenge