filmov
tv
Array - 50: Find first missing positive number in given array
Показать описание
Solution - 1: Using Sorting
- We sort the array
- Now start iterating the element: Ignore negative element & as soon as you get positive number, keep monitoring numbers
- Return first missing positive value
Time Complexity: O(nlog(n)), where n is number of values in array
Space Complexity: O(1)
Solution - 2:
- We'll start from 0th index & iterate all elements of all array
- If arr value is positive & less than equal to array lenegth & arr[i] is not arr[arr[i] - 1], then we need to swap the value, So we get the index value & put this value to it's correct index
- If it's not the case, then we move to next index.
- Now we traverse array values and if arr value is not equal to index + 1, retun first missing number (index + 1)
Time Complexity: O(n)
Space Complexity: O(1)
For more info, please see the video.
CHECK OUT CODING SIMPLIFIED
★☆★ VIEW THE BLOG POST: ★☆★
I started my YouTube channel, Coding Simplified, during Dec of 2015.
Since then, I've published over 500+ videos.
★☆★ SUBSCRIBE TO ME ON YOUTUBE: ★☆★
★☆★ Send us mail at: ★☆★
- We sort the array
- Now start iterating the element: Ignore negative element & as soon as you get positive number, keep monitoring numbers
- Return first missing positive value
Time Complexity: O(nlog(n)), where n is number of values in array
Space Complexity: O(1)
Solution - 2:
- We'll start from 0th index & iterate all elements of all array
- If arr value is positive & less than equal to array lenegth & arr[i] is not arr[arr[i] - 1], then we need to swap the value, So we get the index value & put this value to it's correct index
- If it's not the case, then we move to next index.
- Now we traverse array values and if arr value is not equal to index + 1, retun first missing number (index + 1)
Time Complexity: O(n)
Space Complexity: O(1)
For more info, please see the video.
CHECK OUT CODING SIMPLIFIED
★☆★ VIEW THE BLOG POST: ★☆★
I started my YouTube channel, Coding Simplified, during Dec of 2015.
Since then, I've published over 500+ videos.
★☆★ SUBSCRIBE TO ME ON YOUTUBE: ★☆★
★☆★ Send us mail at: ★☆★
Array - 50: Find first missing positive number in given array
Find maximum element in an array (Largest element)
Array - 51: Find the first K missing Positive number
Array: First repeating element
LeetCode Find First and Last Position of Element in Sorted Array Solution Explained - Java
Array: First non repeating elements
Find first two largest value from NumPy array || Python interview Question
How to find repeating elements in an array in C++
Find the first repeating element in an array of integers in O(n) time
How To Get Array Input From A User In Java Using Scanner
Algorithms in Swift: Find all two elements pair in the array that add up to given sum
P5 | Program to Input Marks of 50 Students in Array & Display Average | C Programming Language
Find missing number in array || GFG coding question
Javascript Problem: First element in an Array - Level: Very Easy
c program to find maximum and minimum element of array | Learn coding
Coding Interview Question | Find one/two Missing Numbers in Array | XOR application
How to search for an element is an Array using Linear Search??
Find If A Value Exists In Array - JavaScript
FOP-Lecture-15 (Array Part-2)- Find First, Second & Third Max, Min, Average, Search occurrence o...
Find the occurrence of an integer in the array. #geeksforgeeks top 50 array questions
C Program to Find First Duplicate Element in Array
Find the Missing Number in an Array | Animation | Coding Interview Question
C-50 Arrays in C - Part 5 | Array Program 2 | C Programming Tutorials
w3resource.com: Java Array Exercise-50
Комментарии