Google interview question

some algorithm problems (leetcode medium)