Need help!

Given an array of integers, find the first missing positive integer in linear time and constant space. In other words, find the lowest positive integer that does not exist in the array. The array can contain duplicates and negative numbers as well.

For example, the input [3, 4, -1, 1] should give 2. The input [1, 2, 0] should give 3.

You can modify the input array in-place.

Plz check my code

a = 1

arr = []

n = input("Enter length of array : ")

for i in range (0,n):


for i in range (0,n):







prob st is confusing
it said 1st pos int
but by looking at test cases
it seems like count of pos int

1 Like

ur logic seems correct
am not much familiar with py so not sure if u can use .count() or not. But if its correct then it shld work.
only edge cases it would fail if it goes out of for loop without printing anything
like if all inputs are -ve or when its like
1 2 3 -1 -1
ur logic wont print 4 rather it will jst terminate the prog


  1. Initialize an array at zero.
    int h[MAX+5]={0}, (MAX=maximum input number)
  2. Change all negative numbers of given array to zero.
  3. Traverse the given array
    for(int i=0;i<n;i++)
    This operation will count the occourence of each element in array.
  4. Traverse the array ‘h’ and find the first positive zero. The index of zero is your answer.