Question bank › Heap
Dsa Heap Hard

Weighted Average by Group

You are given a list of records with each record containing a group identifier, a value, and a weight. Your task is to compute the weighted average for each group. Input starts with an integer N for the number of records followed by N lines where each line contains a group identifier, a value, and a weight. Output the weighted averages for each group, sorted by group identifier. Each weighted average should be printed on a new line. Use heaps for efficient aggregation of data. Example: Input: 3 group1 10 2 group1 20 3 group2 15 1 Output: group1 16.0 group2 15.0

Key concepts

heapweighted averagedata aggregation

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.