Find top-k frequent elements with tiebreaks | Meta Interview Question