Pergunta de entrevista da empresa Bank BTPN

Simple algorithm puzzle that should be coded live