Google interview question

modified lc hard, ood implementation