Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Non-Maximum Suppression for Boxes

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Non-Maximum Suppression for Boxes. Start with the requirements on the right.

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.

Problem

Given a list of 2D bounding boxes and a list of confidence scores of equal length, implement Non-Maximum Suppression (NMS). Each box is represented as [x1, y1, x2, y2], where (x1, y1) is the top-left corner and (x2, y2) is the bottom-right corner. Return the indices of the boxes kept after suppressing boxes whose Intersection over Union (IoU) with a higher-scoring box is greater than a given threshold.

Constraints

  • 1 <= len(boxes) == len(scores) <= 10^4
  • boxes[i].length == 4
  • 0 <= x1 < x2 <= 10^6
  • 0 <= y1 < y2 <= 10^6
  • 0.0 <= scores[i] <= 1.0

Function Signature

def non_max_suppression(boxes, scores, iou_threshold):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output