Search
First Missing Integer Interviewbit Solution
- illuminati
- Sep 1, 2020
- 1 min read
Updated: May 29, 2021
Problem: First Missing Integer
Problem Description:
Given an unsorted integer array, find the first missing positive integer.
Example:
Given [1,2,0] return 3,
[3,4,-1,1] return 2,
[-8, -7, -6] returns 1
Your algorithm should run in O(n) time and use constant space.
Solution:
Method 1:
Time Complexity: O(N)
Space Complexity: O(N)
Method 2:
Time Complexity: O(NlogN)
Space Complexity: O(1)
Method 3:
Time Complexity: O(N)
Space Complexity: O(1)
Recent Posts
See AllYou are given an array of N non-negative integers, A0, A1 ,…, AN-1.Considering each array element Ai as the edge length of some line segment
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives
It looks in the code given above , first approach missed space constraints and second approach missed time constraint. ( As per InterviewBit problem statement)