FactSet Interview Question

fruit basket(leet code) one qn from gfg