Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Smallest Missing Positive Integer

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

Your question is Smallest Missing Positive Integer. 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 an array A of N integers, find the smallest positive integer greater than 0 that does not occur in A.

Implement def missing_positive(A):. Return the missing integer. The array may contain negative values, zero, duplicates, and values larger than N.

Constraints

  • 0 <= N <= 100000
  • The input contains integers only
  • The function may modify A in place
  • Return exactly one positive integer

Function Signature

def missing_positive(A):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output