Scale Interview Question

Leetcode hard for the final round