First missing Positive | Programming Interview Preparation Must Do programming questions
Vložit
- čas přidán 18. 11. 2022
- 🟠 Problem link of First missing Positive: bit.ly/3Ec7tVN
This is the video under the series of Must do Programming Questions. First missing Positive
Join My Telegram channel for more Updates: telegram.me/helloworldbyprince
complete DSA preparation: github.com/Prince-1501/Comple...
----------------------------------------------------------------------------------------
*Follow me *
LinkedIn► / iamprince
Facebook► / helloworldofficials
Instagram► / helloworldbyprince
Twitter► / prince_king_
Telegram► telegram.me/helloworldbyprince
----------------------------------------------------------------------------------------
►Our Playlists on:-
🔥 Tree: • Tree Data Structure & ...
🔥 Stack & Queue: • Stack & Queue Data Str...
🔥 Hashing: • Hashing Data Structure...
🔥 Graph: • Graph Data Structure &...
🔥 Matrix: • Matrix (Multidimension...
🔥 Heap: • Heap Data Structure & ...
🔥 Linked List: • Linked List Data Struc...
🔥 STL: • Standard Template Libr...
🔥 Leetcode: • LeetCode Solutions And...
🔥Competitive Programming: • Full course in Competi...
🔥 C++ Full Course: • C++ full Course in HINDI
🔥 Algorithms: • L-01 || Prefix Sum Arr...
🔥 Data Structure: • Data Structures with C...
------------------------------------------------------------------------
🌟 Please leave a LIKE ❤️ and SUBSCRIBE for more AMAZING content! 🌟
✨ Tags ✨
Implement Heap from class c++
K largest element
K largest element min heap
min-heap Delete operation in a heap
Introduction to the heap data structure
heap playlist Hello world
heap practice problems
heap practice problems gfg
leetcode heap questions
leetcode heap
heap hello world
Types of the heap in Data structure & algorithms
playlist heap Hindi
question asked in Google
off-campus placement
Practice heap data structure
heap in a data structure in Hindi
heap Full playlist for Beginners
algorithms
heap
data structure
gate computer science preparation
programming languages
Comment "#Princebhai" if you read this 😉😉
#Heap #decreaseKey() #programming
there is one edge case it won't work with duplicate value ex - [1, 1] you will mark 1 by -1 then you will go to second index then you will again do -1 * -1 then it will become 1 but we have to return 2 ans for that we can write one edge case if(arr[index]>0) {arr[index] *= -1 ; }
Prince bhaiya I am learning from your VIDEOS . Thank you very much
Today I will definetely complete LINKED LIST series and tommorow TREES series .
I am in third year . I have very less time left . I HOPE I will make it to a good company .
As soon as I complete atleast basic DSA I will inform you about it .
Once again thanks .
I am also learning back end development NODE JS from youtube and as soon as I am confident in it and develop projects worth watching I will contact you for help.
Thanks again , you are doing an amazing job for community .
May god always keep you healthy.
Great work ,keep going
bhaiya faltu gyan mt chodo jo que.. h upr focus to achha hain , oversmart to aise bnte ho jese sunder pichai ko bhi aapne hi pdaya ho , baki pda achhe rhe ho bs aapki ye chiz irritate krti h
Bsdk pahle tu to aache se padh le baad me bhaiya ko bola kuch
🤣🤣🤣
🤣🤣🤣🤣🤣🤣
keep uploading this kind of video please we miss u bro
It will be nums[index]=-1*abs(nums[index])
this code does not work in gfg !! fail to satisfy all test case .
it won't work for duplicate as well as for negative.
Very helpful videos!
Glad to hear that!
hello, i am complete BCA in 2014 now i want to job for java background but i am late does it's possible to gets jobs..please reply me....
Wahh bhaia mjaa aagya🎉
Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
happy birthdayyyyyyyyy to you❣❣
Amazing concept 🤩
Minor fix required for duplicate items ( [2,3,1,1] ) its returns wrong answer, so fix is that
if(idx < n && nums[idx] > 0) {
nums[idx] *= -1;
}
Air gfg me teat case fail ho raha hai
test case wrong aayenge first sort the array sort(arr,arr+n); then iterate
nums =[1,1]. for this case it will fail.....
haa leetcode pe
int firstMissingPositive(vector& nums) {
for(int i=0;i
bhaiya it will fail for [1,1]
class Solution {
public:
int firstMissingPositive(vector& nums) {
for(int i = 0;i < nums.size(); i++){
if(nums[i] 0){
nums[index]*=-1;
}
}
for(int i = 0;i < nums.size();i++){
if(nums[i] > 0){
return i+1;
}
}
return nums.size()+1;
}
};
bhaiya it will fail on test case 1,1
Why
@@HelloWorldbyprince check on leetcode plz
@@HelloWorldbyprince int firstMissingPositive(vector& nums) {
for(int i=0;i
int firstMissingPositive(vector& nums) {
for(int i=0;i
It will fail when any +ve number have even frequency then first one make it negative and second one positive(initial stage). So to solve it just make an extra check arr[index]>0 , only then make it negative(line no 13 in code ). so condition will be index0.
The following code works fine and passes all the test cases.
//Approach 2
//T.C -> O(N), S.C -> O(1)
//Uses concept of hashing
int missingNumber_two(int arr[], int n){
for(int i = 0; i < n; i++){
if(arr[i] 0){ //arr[index] > 0 to avoid considering the duplicate cases
arr[index] *= -1;
}
}
//In the below loop, if we find any element greater than 0, then that means (element's index + 1) element is not present in the array
for(int i = 0; i < n; i++){
if(arr[i] > 0){
return i + 1;
}
}
return n + 1; //If all the elements from 1 to n are present, then smallest element that is missing will be n + 1.
}
thanks
what about negative numbers ex :[-1,-2,-3,-4,-5] ?
☹️ 𝐩𝓻Ỗ𝓂Ø𝓈M
😅
playlist ke promotion se jada content pe dhiyan de dete jada like mil jaate or accha bhi lgta.....har video me bas playlist playlist
bakbass solution
Fails for [1,1], Dislike not work in leetcode
int firstMissingPositive(vector& nums) {
for(int i=0;i
check that value at that indes shloud ne positive then make it negative
AC SOLUTION
int n = nums.size();
// work on -ve and 0 element
for(int i = 0; i < n; i++) {
if(nums[i]
Wrong Solution
input
6
1 1 -2 4 5 2
Expected output
3
your Output
1