Top k frequent tags
A photo library shows its most-used tags first. Given the list of every tag application (repeats meaningful) and an integer k (k >= 1), return the k most frequently used distinct tags. Order the result by frequency, highest first; break frequency ties alphabetically (lexicographically ascending). If fewer than k distinct tags exist, return them all under the same ordering. For example, tags ["pop", "rock", "pop", "jazz", "rock", "pop"] with k = 2 give ["pop", "rock"], and ["t", "t", "s", "s", "r"] with k = 1 gives ["s"].
top_tags(tags: list[str], k: int) → list[str][["pop","rock","pop","jazz","rock","pop"],2]out["pop","rock"]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.
[["pop","rock","pop","jazz","rock","pop"],2]["pop","rock"]not run yetsample