Google interview question

Leetcode hard question, can't share because NDA