Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Non-Maximum Suppression for Boxes
00:00
5 left

Non-Maximum Suppression for Boxes

MediumPython

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):
Interviewer

Your question is Non-Maximum Suppression for Boxes. 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
Sign up free to run your codeLog inLn 2
Run your code to see test output here.