Pergunta de entrevista da empresa JPMorganChase

Algorithm type question using loops. Interviewer was nice and tried to give hints.