Approach

Written by Jasper Di Francesco from CSESoc Education.

My approach was similar to finding the maximum value in an array. Firstly we scan in the number of groups, then we iterate through each one, checking if the sum of it's ages is greater than the current maximum.

As we know that ages cannot be negative, we can give the initial maximum a default value of 0.

If the sum of the current group's ages XX is greater than the current maxiumum MM, then we change MM to be equal to XX and update the group number to be the current group.

As long as we only change MM when XX is greater than MM and not when it is greater than or equal to, then we ensure we always return the lowest group number.