- Encapsulate the solution in a function.
- Minimize allocations
- Simplify by using simple loops.
- Use the same loops for totals summation and subject summation and low average.
- The order of an average, sum/n, and a sum is the same, we don't need to calculate sum/n.
- At the end, we already have the student marks sum, so simply subtract the low average mark for the returned total.