Skip to content
DeepForgeby svx
All problems
EasyML Fundamentalsml-036

Majority Class

Problem

Return the most frequent label in labels, breaking ties by choosing the smallest label. Empty input returns None.

Hint

Count labels, iterate keys in sorted order, and keep the count leader.

Test cases

case 1
in: [[1,1,0,0,1]]
expected: 1
case 2
in: [["b","a","b","a"]]
expected: "a"
case 3
in: [[3]]
expected: 3
case 4
in: [[]]
expected: null
Starter codePython
def majority_class(labels):
    # Your code here
    pass

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