Solve frequency and tree-completeness problems | Meta Interview Question