Google Interview Question

Leetcode hard question, can't share because NDA