Amazon Interview Question

How would you calculate these statistics (e.g. group wise mean) without a loop?