- Related Questions & Answers
- First Missing Positive in Python
- Program to find lowest possible integer that is missing in the array in Python
- Find missing numbers in a sorted list range in Python
- Python program to reverse bits of a positive integer number?
- Python program to find missing and additional values in two lists?
- Print first k digits of 1/n where n is a positive integer in C Program
- Find Positive Integer Solution for a Given Equation in C++
- Program to find all missing numbers from 1 to N in Python
- Find missing elements in List in Python
- Java program to reverse bits of a positive integer number
- Add a positive integer constraint to an integer column in MySQL?
- Maximum positive integer divisible by C and is in the range [A, B] in C++
- Minimum positive integer divisible by C and is not in range [A, B] in C++
- PHP program to find the first ‘n’ numbers that are missing in an array
- Positive integer square array JavaScript

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Suppose we have a list of sorted list of distinct integers of size n, we have to find the first positive number in range [1 to n+1] that is not present in the array.

So, if the input is like nums = [0,5,1], then the output will be 2, as 2 is the first missing number in range 1 to 5.

To solve this, we will follow these steps −

target := 1

for each i in arr, do

if i is same as target, then

target := target + 1

return target

Let us see the following implementation to get better understanding −

class Solution: def solve(self, arr): target = 1 for i in arr: if i == target: target += 1 return target ob = Solution() nums = [0,5,1] print(ob.solve(nums))

[0,5,1]

2

Advertisements