- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to find lowest possible integer that is missing in the array in Python
Suppose we have a list of numbers called nums, we have to find the first missing positive number. In other words, the lowest positive number that does not present in the array. The array can contain duplicates and negative numbers as well.
So, if the input is like nums = [0,3,1], then the output will be 2
To solve this, we will follow these steps −
nums := a set with all positive numbers present in nums
if nums is null, then
return 1
for i in range 1 to size of nums + 2, do
if i is not present in nums, then
return i
Let us see the following implementation to get better understanding −
Example
class Solution: def solve(self, nums): nums = set(num for num in nums if num > 0) if not nums: return 1 for i in range(1, len(nums) + 2): if i not in nums: return i ob = Solution() nums = [0,3,1] print(ob.solve(nums))
Input
[0,3,1]
Output
2
- Related Articles
- Program to find first positive missing integer in range in Python
- Program to find kth missing positive number in an array in Python
- PHP program to find the first ‘n’ numbers that are missing in an array
- PHP program to find the numbers within a given array that are missing
- Program to find minimum possible integer after at most k adjacent swaps on digits in Python
- What is the maximum possible value of an integer in Python?
- PHP program to find missing elements from an array
- Python program to find missing and additional values in two lists?
- Program to find all missing numbers from 1 to N in Python
- Program to find lowest sum of pairs greater than given target in Python
- C# program to find all duplicate elements in an integer array
- Program to Find Out Median of an Integer Array in C++
- Program to find the final ranking of teams in order from highest to lowest rank in python
- Write a program in Python to find the lowest value in a given DataFrame and store the lowest value in a new row and column
- Program to find length of longest possible stick in Python?

Advertisements