NextCapital Group interview question

easy hackerrank challenge