← 返回 sofi 的题目列表Second Most Frequent GIF Tag
类型:qbank
Given GIF or image metadata in a flat triple format, find the tag with the second-highest frequency under tie rules.
Requirements
Input is a flat List<String> such as {id1, name1, tag1, id2, name2, tag2, ...}.
Count tag frequencies from the third item of every triple.
Return the tag with the second-highest frequency.
If all tags have the same count, return "notag".
If multiple tags tie for the highest frequency, there is no second-highest tag and the return value is "notag".
Time complexity should be no worse than O(N).
In the onsite variant, if there are multiple second-place tags, return the first such tag by input order.
Notes
Candidates used or considered hashmap counting plus quickselect or heap selection, but a two-pass frequency-rank scan is enough for the stated O(N) target.
Hidden tests cover tie semantics; clarify whether ties at first rank, second rank, or both should suppress the answer.