All problems
Person Box Aspect Filter
Problem
Keep boxes whose width/height aspect ratio lies within a range.
Boxes are [x1, y1, x2, y2] with continuous coordinates; keep a box when min_ratio <= (x2 - x1) / (y2 - y1) <= max_ratio, preserving order.
Test cases
case 1
in: [[[0,0,4,2],[0,0,1,2],[0,0,6,2]],1,3]
expected: [[0,0,4,2],[0,0,6,2]]
case 2
in: [[[0,0,4,2],[0,0,1,2],[0,0,6,2]],0.4,0.6]
expected: [[0,0,1,2]]
case 3
in: [[[0,0,2,2]],2,1]
expected: []
Starter codePython
def filter_aspect_ratio(boxes, min_ratio, max_ratio):
# Your code here
pass3 test cases · run your code against them in the editor