Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-162

Rank of Each Element per Row

Problem

Replace every entry of A with its rank within its row, where rank = 1 + the number of entries strictly smaller than it.

Tied entries therefore receive the same rank. Return integer ranks.

Hint

Competition ranking: tied values share the rank of the first occurrence.

Test cases

case 1
in: [[[3,1,2]]]
expected: [[3,1,2]]
case 2
in: [[[10,20,20]]]
expected: [[1,2,2]]
case 3
in: [[[5,4,3,2,1]]]
expected: [[5,4,3,2,1]]
case 4
in: [[[7,7,7]]]
expected: [[1,1,1]]
Starter codePython
def row_ranks(A):
    # Your code here
    pass

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