Skip to content
DeepForgeby svx
All problems
EasyInformation Theoryinfo-320

Majority Label of a Node

Problem

Return the most frequent label in a list, breaking ties by choosing the lexicographically smallest label. Return an empty string for an empty list.

Hint

Track counts, then compare count and label together.

Test cases

case 1
in: [["a","b","a"]]
expected: "a"
case 2
in: [["b","a"]]
expected: "a"
case 3
in: [[]]
expected: ""
case 4
in: [["c","b","c","b"]]
expected: "b"
case 5
in: [["z"]]
expected: "z"
Starter codePython
def majority_label(labels):
    # Your code here
    pass

5 test cases · run your code against them in the editor