Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Compute IoU for Tracking
00:00
5 left

Compute IoU for Tracking

MediumPython

Problem

Given a list of bounding boxes representing detected objects, write a function to calculate Intersection over Union (IoU) for tracking in Motional perception pipelines.

Implement calculate_iou(box_a, box_b), where each box is [x_min, y_min, x_max, y_max]. Return a floating-point IoU between 0.0 and 1.0. Treat boxes with zero or negative area, and boxes that do not overlap, as having an IoU of 0.0.

Input and Output

The function receives two lists of four numbers and returns a float. Use the standard definition: intersection_area / union_area, where union_area = area_a + area_b - intersection_area.

Constraints

  • Each input box contains exactly four finite numeric coordinates.
  • Coordinates may be negative.
  • Coordinates may be supplied in either corner order.
  • The function returns a floating-point value in the range [0.0, 1.0].

Function Signature

def calculate_iou(box_a, box_b):
Interviewer

Your question is Compute IoU for Tracking. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.