Code RoomGroup by having aggregation
MediumPrep Room Coding #329

Group by having aggregation

CodingDatabases & SQLMid–Senior~25 min

You are implementing the GROUP BY / HAVING stage of a query engine. Given a list of rows, each a dict with keys 'dept' (string) and 'salary' (int), group the rows by 'dept', compute the average salary per group, and return only the groups whose average salary is strictly greater than `threshold`. Return a list of [dept, avg_salary] pairs where avg_salary is the integer floor of the average. Order the result by dept ascending. There are at most 10000 rows; salaries are non-negative.

Implement
having_avg_salary(rows: list[dict], threshold: int) → list[list]
Examples
in[[{"dept":"eng","salary":100},{"dept":"eng","salary":200},{"dept":"sales","salary":50}],80]out[["eng",150]]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 25 min
InputExpectedGot
[[{"dept":"eng","salary":100},{"dept":"eng","salary":200},{"dept":"sales","salary":50}],80][["eng",150]]not run yetsample