Google interview question

union find structure