Google interview question

Both question is a variant of leet code problem.