STMicroelectronics Interview Question

candle puzzle, basic java