Untitled
unknown
python
2 years ago
782 B
8
Indexable
def getMeanRankCount(rank): n = len(rank) mean_counts = [0] * n # Calculate the cumulative sum of ranks cumulative_sum = [0] for i in range(n): cumulative_sum.append(cumulative_sum[-1] + rank[i]) # Sliding window to calculate mean ranks for window_size in range(1, n + 1): for start in range(n - window_size + 1): end = start + window_size - 1 mean_value = (cumulative_sum[end + 1] - cumulative_sum[start]) / window_size if mean_value == int(mean_value): # Check if the mean is an integer mean_value = int(mean_value) mean_counts[mean_value - 1] += 1 return mean_counts # Test case rank = [1, 2, 3, 4, 5] print(getMeanRankCount(rank)) # Output: [1, 2, 3, 2, 1]
Editor is loading...