Pergunta de entrevista da empresa Expedia Group

The question around the efficiency algorithm I have posted above