Pergunta de entrevista da empresa Amazon

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