Skip to content
DeepForgeby svx
All problems
MediumNLPnlp-220

Reading Order Check

Problem

Return the indices of boxes sorted into reading order: by vertical center, then horizontal center, then original index.

Boxes are [x1, y1, x2, y2], and an empty box list gives an empty order.

Hint

Compute box centers first, then sort with the composite key.

Test cases

case 1
in: [[[0,0,10,10],[20,0,30,10],[0,20,10,30],[20,20,30,30]]]
expected: [0,1,2,3]
case 2
in: [[[20,20,30,30],[0,0,10,10],[30,0,40,10],[10,20,20,30]]]
expected: [1,2,3,0]
case 3
in: [[]]
expected: []
case 4
in: [[[0,0,1,1]]]
expected: [0]
Starter codePython
def reading_order_check(boxes):
    # Your code here
    pass

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