Capstone — Discovery Feed
In short: the discovery tab is where this section's three structures meet. A listener who loves Rock types "ne", and the feed should show the best few Rock tracks — Punk and Metal included — whose titles start with "ne", most-played first. Three questions, three structures: the genre tree says which genres count, a trie says which titles match, and a heap picks the top k. Each stage hands the next fewer candidates, so the heap — the most expensive step per item — only ever sorts the tracks that could possibly win.

Pin the spec down before writing code
discovery_feed(genres, tracks, favorite, prefix, k) takes:
genres— the genre tree as a level-order list,Nonefor a missing childtracks—[title, genre, plays]triples; titles are unique and lowercasefavorite— a genre; the feed draws from it and every genre beneath itprefix— what's been typed so far;""matches everythingk— how many titles to return
It returns up to k titles, most plays first, ties broken alphabetically.
A favorite that isn't in the tree gives [], and a track whose genre isn't in
the tree is never picked. Pinning ties down isn't pedantry: two listeners
with the same taste must see the same feed, and a test can only check an
answer that has exactly one right value.