You are given a list of strings in the following repeating order:
[id1, name1, tag1, id2, name2, tag2, ...]
So every 3 consecutive elements describe one record: (id, name, tag).
Return the tag that is the second most frequent among all records’ tags.
Tie/edge-case rules:
-
If there is
no
“second most frequent” tag because
all tags have the same count
(i.e., there is only one distinct frequency), return
"notag"
.
-
If there are
multiple
tags tied for second most frequent, return the one whose
first appearance in the input list
occurs earliest.
Constraints/expectations:
-
Run time should be O(n).
-
You may assume the input length is a multiple of 3.
Example:
Input: ["1","A","x","2","B","y","3","C","y","4","D","x","5","E","z"]
Counts: x=2, y=2, z=1 → second most frequent is z → return "z".
Write a function to compute the required tag.