Pergunta de entrevista da empresa General Dynamics

I was asked the programming problem 2 sum