Pergunta de entrevista da empresa Yelp

Time and space complexity of the problem