Google interview question

Leetcode medium based on data structures and simple algorithm