Code RoomPlays by region
MediumPrep Room Coding #452

Plays by region

CodingAlgorithms & data structuresEntry–Mid~14 min

A podcast dashboard rolls listener plays up by region. Each play is recorded as a two-letter country code, and a reference table maps country codes to region names. Codes missing from the table are grouped under the literal region "other". Given the list of play country codes and the reference table, return a dictionary mapping each region name that received at least one play to its play count. For example, plays ["us", "de", "us", "xx"] with table {"us": "na", "de": "eu"} give {"na": 2, "eu": 1, "other": 1}. An empty play list returns an empty dictionary.

Implement
plays_by_region(codes: list[str], regions: dict[str,str]) → dict[str,int]
Examples
in[["us","de","us","xx"],{"de":"eu","us":"na"}]out{"eu":1,"na":2,"other":1}
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 14 min
InputExpectedGot
[["us","de","us","xx"],{"de":"eu","us":"na"}]{"eu":1,"na":2,"other":1}not run yetsample