def max_weight_node(arr): score = collections.defaultdict(int) for i, e in enumerate(arr): if e ==-1: continue score[e] += i return max(score, key=lambda x: (score[x], x))
23 4 4 1 4 13 8 8 8 0 8 14 9 15 11 -1 10 15 22 22 22 22 22 21
Standard output is empty
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!