Pergunta de entrevista da empresa Bloomberg

simple Leetcode style Tree question(1 hour); struggled with time/space complexity, interviewers helped to reach the correct time/space complexity