Skip to content
DeepForgeby svx
All problems
MediumTime Seriests-115

Mann-Kendall Statistic

Problem

Compute the Mann-Kendall trend statistic S = sum over i < j of sign(series[j] - series[i]), counting +1 for increases and -1 for decreases.

Positive S indicates an upward trend, negative S a downward trend, and 0 no monotone tendency.

Hint

It is a nonparametric test: only the signs of pairs matter, not magnitudes.

Test cases

case 1
in: [[1,2,3,4]]
expected: 6
case 2
in: [[4,3,2,1]]
expected: -6
case 3
in: [[1,3,2]]
expected: 1
case 4
in: [[5,5,5]]
expected: 0
Starter codePython
def mann_kendall_statistic(series):
    # Your code here
    pass

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