FactSet Interview Question

They asked to write java code for some choclates problem