Google Interview Question

Solve this leet code under 30min