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 ; }
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
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; }
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.
solution :class Solution { public int firstMissingPositive(int[] nums) { int n = nums.length; for (int i = 0; i < n; i++) { while (nums[i] > 0 && nums[i]
Muje aapke channel se dsa karna hai but playlist wale section mein bohot sare playlist hai to aap please jo imp hai vo playlists kaa title bol do Please reply
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. }
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 ; }
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
🤣🤣🤣
🤣🤣🤣🤣🤣🤣
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
It will be nums[index]=-1*abs(nums[index])
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.
this code does not work in gfg !! fail to satisfy all test case .
it won't work for duplicate as well as for negative.
keep uploading this kind of video please we miss u bro
solution :class Solution {
public int firstMissingPositive(int[] nums) {
int n = nums.length;
for (int i = 0; i < n; i++) {
while (nums[i] > 0 && nums[i]
if(idx < n && nums[idx] > 0) {
nums[idx] *= -1;
} add this condition it will work probably he forgot nums[idx]>0 for duplicates
Great work ,keep going
Muje aapke channel se dsa karna hai but
playlist wale section mein bohot sare playlist hai to aap please jo imp hai vo playlists kaa title bol do
Please reply
Follow the sequence
Hashing
Linked list
Stack and queue
Heap
Tree
Graph
DP
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....
test case wrong aayenge first sort the array sort(arr,arr+n); then iterate
happy birthdayyyyyyyyy to you❣❣
Very helpful videos!
Glad to hear that!
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.
Wahh bhaia mjaa aagya🎉
Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
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] ?
kyu hero banne ki kosis kar raha comment m code dalke
@@rockerzgaming710Kosis? Mai already hero hu bhai. Google mai search karke dekho mera naam, samaj aajayega.
nums =[1,1]. for this case it will fail.....
haa leetcode pe
int firstMissingPositive(vector& nums) {
for(int i=0;i
@@JitendraKumar-ud5yc Thank you
1. convert all negative into postive
2. mark all present number
3. check element is present or not
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;
}
};
playlist ke promotion se jada content pe dhiyan de dete jada like mil jaate or accha bhi lgta.....har video me bas playlist playlist
AC SOLUTION
int n = nums.size();
// work on -ve and 0 element
for(int i = 0; i < n; i++) {
if(nums[i]
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
bakbass solution
☹️ 𝐩𝓻Ỗ𝓂Ø𝓈M
😅
Wrong Solution
input
6
1 1 -2 4 5 2
Expected output
3
your Output
1