Google interview question

Difficult data structure and algorithms question