Тёмный
No video :(

Find missing number in an array 

Techdose
Подписаться 173 тыс.
Просмотров 129 тыс.
50% 1

Опубликовано:

 

21 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 141   
@divakarkumar1461
@divakarkumar1461 3 года назад
Sort the array then For(int i=0;i
@sarvesh545
@sarvesh545 2 месяца назад
what if the range is random means like 55 to 78
@deepjyotidebnath4122
@deepjyotidebnath4122 3 года назад
Great video ! 🙌 I understand the XOR operation by this video.
@dikshakatake5739
@dikshakatake5739 4 года назад
Great video ! 🙌 No need to research the best approach just watch your videos and you are good to go ! Thanks🙌🙌
@techdose4u
@techdose4u 4 года назад
Welcome :)
@unknow2096
@unknow2096 3 года назад
@@techdose4u How to find more then one missing element???
@akashkewar
@akashkewar 2 года назад
@@unknow2096 one simple approach could be, create a set containing (0-n) elements, loop via that list and remove the element from the set. The elements remaining in the set are your missing elements.
@khushichaurasia7599
@khushichaurasia7599 3 года назад
Your explaining level ....😍😍😍😍
@techdose4u
@techdose4u 3 года назад
:)
@surajdevv
@surajdevv 18 дней назад
Sum of n natural number approach is easy but does not work on different test cases only works for certain test cases
@aaditpalande7478
@aaditpalande7478 Год назад
Thank you sir , Just one question that how can I build my mind to think for the solution in such various approaches
@Firstusee256
@Firstusee256 4 года назад
If the given array is sorted , then binary search can be applied ( logn) time
@techdose4u
@techdose4u 4 года назад
Yes you are correct, but only if the array is sorted, while XOR works in all cases :)
@atuladityax
@atuladityax 24 дня назад
An excellent video
@iamnimish
@iamnimish Год назад
XORing all the elements & then XORing the numbers till n. And then XORing both tof the obtained results. This brings us the left out element as XOR of a no with itself is zero(like in binary).
@aayushverma1264
@aayushverma1264 4 года назад
We can also try subtracting method. if (arr[i] - arr[i-1] == 2) then missing number = arr[i] - 1. Time complexity is O(n) and Space Complexity is O(1).
@TedAsiamah
@TedAsiamah 4 года назад
This wont work for an unsorted array.
@rickseth9207
@rickseth9207 Год назад
tried this but the problem is if the element missing is after the first or before the first place then problem arises
@surajtopal9940
@surajtopal9940 3 года назад
XOR one is really cool . I tried with -negative value and array is not sorted still working perfect . Thank a lot sir ji
@har.preet.singh.
@har.preet.singh. 3 года назад
Hey brother! Can you please share the code, if possible? It'll be very nice of you, if you can.
@surajtopal9940
@surajtopal9940 3 года назад
@@har.preet.singh. sorry brother , you are late. Actually I practice in online compiler we cannot save program .
@surajtopal9940
@surajtopal9940 3 года назад
try yourself brother , if you face any difficulty send your code here then i will help you .
@har.preet.singh.
@har.preet.singh. 3 года назад
@@surajtopal9940 Here's my python code which isn't working. def func(N,A): new=[] for n in range(max(A)+1): new.append(-1) for i in range(N): if A[i]>=0: new[A[i]]=True for j in range(1,max(A)+1): if new[j]==True: return j+1 break L=[] N=int(input('Enter the number of elements: ')) print('Now, enter the',N, 'elements:') for n in range(N): L.append(int(input())) print(func(N,L))
@surajtopal9940
@surajtopal9940 3 года назад
@@har.preet.singh. brother this is different approach use XOR operation. It is very easy. You just to XOR all the value of the array one by one and put it in the result variable after than you need to do the loop till n and XOR all in the result1 then result ^ result1 and you will get your answer.
@killeraloo3247
@killeraloo3247 11 месяцев назад
mast vide thi, sare methods samajh aa gye. Thanq.
@nitin-7870
@nitin-7870 Год назад
that was just amazing, before this video i was doing like sorting all the element in the array and finding all the element whether if it is at correct index for not
@shivamkumar-hu3bv
@shivamkumar-hu3bv 2 года назад
From where n=5 comes ??
@Cloud-577
@Cloud-577 2 года назад
note that xor of any number repeats every four digits. so you ca use mod to predetermine the xor of Len(nums). then to find the missing number find the xor of the nums values ONLY. finally return the xor of Len(nums).^ xor of the nums values
@dineshverma-in7on
@dineshverma-in7on 2 года назад
use binary search, time complexity will be logN
@rashibansal7357
@rashibansal7357 4 года назад
what if we sort the array and then start comparing if each element is equal to its index, wherever the condition is a false return that index value.
@f2s654
@f2s654 4 года назад
sorting complexity nlogn we have to do it in N :P
@techdose4u
@techdose4u 4 года назад
😂
@techdose4u
@techdose4u 4 года назад
Simply try XOR
@yaswanthp2294
@yaswanthp2294 2 года назад
Yes
@oldguardkiller8408
@oldguardkiller8408 Год назад
We can Also Use Cyle Sort
@cb559
@cb559 4 года назад
1 and 2 are impratical solution it wont work If negative number is present or missing number not in between. see problem 41 leet code
@kartikbhanderi9210
@kartikbhanderi9210 4 года назад
n*(n+1)/2 - sum of array elements Will also work 😄🍻
@techdose4u
@techdose4u 4 года назад
True. But still O(N) 😁
@rakibulislam2452
@rakibulislam2452 4 года назад
@@techdose4u in python no issue with integer overflow dude
@JohnLee-xl2ut
@JohnLee-xl2ut 4 года назад
Is it n because it is the biggest number in the array?
@kartikbhanderi9210
@kartikbhanderi9210 4 года назад
@@JohnLee-xl2ut it's the formula of arithmetic progression , where we are taking 'n' as last term...
@JohnLee-xl2ut
@JohnLee-xl2ut 4 года назад
@Kartik Bhanderi thanks mate i taught it was always the biggest number. But it is the last number in an array thanks mate :)
@creativeMinds1603
@creativeMinds1603 2 месяца назад
Great explanation 😃
@kommunagasheshu3601
@kommunagasheshu3601 Год назад
As well as please explain code for the problem.
@FANSasFRIENDS
@FANSasFRIENDS 2 года назад
Sir, kindly explain what is overflow for this case.
@yaswanthp2294
@yaswanthp2294 2 года назад
Overflow occurs when we sum large numbers. In java integer has some range. If sum goes beyond range, it will cause overflow and doesn't give proper results.
@suhailsiddiqui840
@suhailsiddiqui840 2 года назад
I think this one is more efficient, in very few cases you have to iterate over whole array. If array is in order. for(int i=0;i
@akashkewar
@akashkewar 2 года назад
The BIG O complexity is still O(N).
@ashuiet
@ashuiet 4 года назад
For input int[] a = {-1, 1, 2, 3, 4, 5, 6, 7} missing Nums : 18 but it should be '0' can you suggest why I am getting .because as per the algo explain by instructor it should be pass for boundary value also : public class MissingNumber2 { private static int missingNumber(int[] input, int n) { int x1 = input[0]; int x2 = 1; for (int i = 1; i < n; i++) { x1 = x1 ^ input[i]; } for (int i = 2; i
@har.preet.singh.
@har.preet.singh. 3 года назад
Can you please share the code of the third approach?
@karanjitrandhawa1515
@karanjitrandhawa1515 2 года назад
int ans1=0,ans2=0; int j=1; for(int i=0;i
@mujahidpasha4440
@mujahidpasha4440 4 года назад
Hi, have you ever come across below question? Given a stream of timestamp and CPU utilisations we need to return the time interval where CPU utilisations was max. Ex input 2d array. [[StartTime, EndTime, cpuUtilization]]
@mujahidpasha4440
@mujahidpasha4440 4 года назад
That's the only information I have about the question... What would be your approach to solve this?
@rajukumar-sv3vj
@rajukumar-sv3vj 11 месяцев назад
sir very good explain thankyou sir ji
@sarvesh545
@sarvesh545 2 месяца назад
what if there are more than one element is missing in an unsorted array
@reenabeeton9856
@reenabeeton9856 3 года назад
Write a Swift program to check if one of the first 4 elements in a given array of integers is a 7. The length of the array may be less than 4. PLS MAKE VIDEO ON IT
@shubhamnehulkar135
@shubhamnehulkar135 4 года назад
what if i have multiple missing numbers??
@techdose4u
@techdose4u 4 года назад
So that will be a totally different question.
@natnaelghirma2617
@natnaelghirma2617 3 года назад
Sir, what about the time it takes to make the second array(the complete one)?
@akashkewar
@akashkewar 2 года назад
You can compute second xor while looping via first array, so it is just O(1* N). You don't really create the second array.
@dovyraj1272
@dovyraj1272 4 года назад
Can v use binary search after sorting
@techdose4u
@techdose4u 4 года назад
You can, if you can related your index with array values.
@souravgorai9481
@souravgorai9481 4 года назад
wont work if there are multiple missing number. Eg.-> i/p- 2 3 1 6 o/p=4. This example wont work
@jeetmishra6681
@jeetmishra6681 4 года назад
Numbers are from 1 to n
@anuragsoni2256
@anuragsoni2256 3 года назад
Thanks! for the video
@techdose4u
@techdose4u 3 года назад
Welcome :)
@roshansinha7001
@roshansinha7001 3 года назад
@@techdose4u How to do this questions in swift language.
@meruguharesh4027
@meruguharesh4027 2 года назад
nice explanation sir
@audioplatform6299
@audioplatform6299 3 года назад
nice solution!
@techdose4u
@techdose4u 3 года назад
Thanks
@IrenJahan-ru5tx
@IrenJahan-ru5tx Год назад
Good video
@probot1436
@probot1436 Год назад
New 2 Method 1.Match the array position no OR 2.find Even or Odd no
@VishalPatel_imvishal
@VishalPatel_imvishal 3 года назад
Java code: ide.geeksforgeeks.org/6tkkn1JzX0
@nishchalbhardwaj4835
@nishchalbhardwaj4835 4 года назад
the sum method won't work if there is a zero in the array
@techdose4u
@techdose4u 4 года назад
The sum technique works for number starting from 1 probably. But for contiguous array, you can use the XOR method which works.
@pandeyshubham1
@pandeyshubham1 3 года назад
No it works for zero as well. My code got accepted using sum method in leetcode.
@atiquesiddiqui710
@atiquesiddiqui710 4 года назад
Very very nice content ❤️ Just sir please us the explanation of pseudo code if you can
@techdose4u
@techdose4u 4 года назад
Yea I am explaining it from past some time.
@atiquesiddiqui710
@atiquesiddiqui710 4 года назад
TECH DOSE sir you are doing a great Work I haven’t found a channel like you on RU-vid honestly sir very very nice 👍🏻 content and to the point 🔥
@atiquesiddiqui710
@atiquesiddiqui710 4 года назад
TECH DOSE sir plzz add a video on number of pairs in an array it would be great 👍🏻
@vinaykumar-sg7xd
@vinaykumar-sg7xd 4 года назад
why u initialized i=2 in second loop
@techdose4u
@techdose4u 4 года назад
Please mention the time while asking question so as to make it easier to refer.
@vinaykumar-sg7xd
@vinaykumar-sg7xd 4 года назад
@@techdose4u in the xor code you provided in the comments
@jatinahuja6929
@jatinahuja6929 3 года назад
Number of terms toh aapne 4 le rkhi hai likha 5 hai
@praveenperumalsamy8005
@praveenperumalsamy8005 3 года назад
Method 2 sum formula not work for all As if 1, 2,5 now answer must be 3,4 but using tis formula we get 7 wrong
@InvincibleMan99
@InvincibleMan99 4 месяца назад
What about -ve numbers [-1, -3] should return 1
@sarvesh545
@sarvesh545 2 месяца назад
then we can use the 2nd method!
@surendharv795
@surendharv795 7 месяцев назад
But the third approach will not work of array elements are repeated.
@rohankumarshah5679
@rohankumarshah5679 2 года назад
brute better optimal -------> awesome.
@unknow2096
@unknow2096 3 года назад
How to find more then one missing element???
@techdose4u
@techdose4u 3 года назад
Try map
@unknow2096
@unknow2096 3 года назад
@@techdose4u what do you mean
@techdose4u
@techdose4u 3 года назад
@@unknow2096 you can keep a hashmap to keep track of what all elements you saw. Rest all in the range of 1 to N will be missing.
@sanjanasain1999
@sanjanasain1999 2 года назад
Your voice is same as apna college channel...
@shaikhzaki3358
@shaikhzaki3358 11 месяцев назад
If the array doesn't contain any missing than
@vishalbhatane1608
@vishalbhatane1608 3 года назад
Thanks
@rajankhunt7002
@rajankhunt7002 2 года назад
GOOD BLOG
@jaydalsaniya6986
@jaydalsaniya6986 4 года назад
What if I do XOR operation between sets in which a={1,2,3} and b={1,2,3,4,5} do i get the answer as {4,5} ???
@techdose4u
@techdose4u 4 года назад
No. You will get your answer = (4 XOR 5). You won't get 4,5 as individual answers and so you will never know about it. If you have only one number missing and you knew the original array then only you can get your answer as missing element. Here, in your example you have 2 missing numbers and so you won't get the missing elements. I hope you got it :)
@yaswanthp2294
@yaswanthp2294 2 года назад
Lovely
@bkmeher9005
@bkmeher9005 Год назад
great
@nitinmahajan3320
@nitinmahajan3320 3 года назад
Can’t we just: 1. initialise counter to array’s zero-th element. 2. Iterate through array increment this counter, wherever the counter and array element does not match - is the answer.
@CodeSuccessChronicle
@CodeSuccessChronicle 3 года назад
the array may not be in sorted form to be able to have a match with value and it's index probably.
@ravikamble8142
@ravikamble8142 4 года назад
in case 1,2,3,4,5 how to find? i am getting 0 .
@JohnLee-xl2ut
@JohnLee-xl2ut 4 года назад
How did the n become 5? is it because it is the biggest?
@abhijeetbhowmik2264
@abhijeetbhowmik2264 4 года назад
Isn't this confusing? Array is unsorted. So there is extra complexity to search for largest number. Only then method second can be used.
@abhijeetbhowmik2264
@abhijeetbhowmik2264 4 года назад
Also if a sorted array is given , simply missing number is a[i] + 1 where a[i+1] - a[i] != 1
@waseemakramshaikh3638
@waseemakramshaikh3638 2 года назад
Methode 2 won't work if 0 present in array
@anujtiwari6842
@anujtiwari6842 Год назад
can you pls give its source code.. it would be really helpful
@MAHTABKHAN-vx9xq
@MAHTABKHAN-vx9xq 2 года назад
There are lot of numbers in a list All of them are whole numbers below 100 They are in not any order Just random whole numbers below 100 We have to find list of numbers which are missing in the series? Anyone solve it ?
@nirajjain8099
@nirajjain8099 2 года назад
Sir can you explain the code for XOR method ??
@karanjitrandhawa1515
@karanjitrandhawa1515 2 года назад
int ans1=0,ans2=0; int j=1; for(int i=0;i
@neerajsinghdhakar9554
@neerajsinghdhakar9554 4 года назад
can u please share the xor source code
@techdose4u
@techdose4u 4 года назад
// Function to get the missing number int getMissingNo(int a[], int n) { // For xor of all the elements in array int x1 = a[0]; // For xor of all the elements from 1 to n+1 int x2 = 1; for (int i = 1; i < n; i++) x1 = x1 ^ a[i]; for (int i = 2; i
@vinaykumar-sg7xd
@vinaykumar-sg7xd 4 года назад
@@techdose4u why u initialized i =2 in second loop
@arif3012
@arif3012 4 года назад
public static int getMissingNo(int arr[] , int n) { int a=1,b=1; for(int i=0;i
@VishalPatel_imvishal
@VishalPatel_imvishal 3 года назад
@@vinaykumar-sg7xd because second loop is for XOR elements from 1 to n. x2 is initialized with 1 so if we start with 1 in second loop then it will become 0 in XOR process. so to eliminate that issue, x2 is initialized with 1 and loop started from 2
@talibqureshi6368
@talibqureshi6368 4 года назад
What if we have multiple numbers missing Ex - [3,4,5,7,8,10,11] How to find first missing number? Please Help
@chirantanacharyya822
@chirantanacharyya822 3 года назад
traverse through the array and check the difference between two consecutive numbers
@yaswanthp2294
@yaswanthp2294 2 года назад
Just use first approach as shown in video. Xor will not work in this case
@abhaymanoharsaxena1174
@abhaymanoharsaxena1174 3 года назад
in second method the n=4 not 5
@techyshivang2634
@techyshivang2634 4 года назад
2nd method also not work for negative number
@akarunx
@akarunx 2 года назад
The problem statement is supposed to be "Find the missing number form an array containing n distinct numbers in the range [0, n]" , Good one from Tech Dose.
@red_app1418
@red_app1418 3 года назад
find missing number in arere
@zeeu
@zeeu 2 года назад
will help if the array is in order function missingNum(arr) { for(i=arr.length-1;i>=0;i--) { if(arr[i] - arr[i-1] == 2) { return arr[i] } } return -1; }
@ZohaibKhan-ug5zg
@ZohaibKhan-ug5zg 2 года назад
Why you are returning the arr[i] ?this will not give us missing number in array for example 1,2,4 and there is 3 missing number then how we get 3 number by returning the arr[i]
@ZohaibKhan-ug5zg
@ZohaibKhan-ug5zg 2 года назад
For correct answer we have to return arr[i]-1 rather than returning the a[i]
@UmeshKumar-zc4zc
@UmeshKumar-zc4zc 3 года назад
None of the method will work in case of duplicates method and when numbers are randomly arranged.
@techdose4u
@techdose4u 3 года назад
This was a simple version where question did not had duplicates.
@UmeshKumar-zc4zc
@UmeshKumar-zc4zc 3 года назад
Then you should add that too. I mean you must specify it's limitations as you are explaining three methods. Anyway that's good at all. Thanks to you.
@techdose4u
@techdose4u 3 года назад
Sure. I will include other version as well.
@abhishekrawat664
@abhishekrawat664 Год назад
Yrr 7 8 9 11 12 ke liye work nahi karega :)
@ravikamble8142
@ravikamble8142 4 года назад
sir code?
@techdose4u
@techdose4u 4 года назад
Please find it on geeks. I am currently uploading CODE for all new videos.
@satyaprakash4598
@satyaprakash4598 4 года назад
Your two approach not working. Ex :- [6,7,8,9]
@sagarlandge3271
@sagarlandge3271 3 года назад
Your input is wrong It should contain all the Integers from 1 to n except one missing no Eg [1,2,3,4,5,7,8,9]
@gajsinghrathore8800
@gajsinghrathore8800 Год назад
i found out better approach T.C->O(LOGN) (IF ARRAY IS SORTED) WE CAN USE BINARY SEARCH int s = 0; int e = N - 1; while (s mid + 1 || arr[mid]
Далее
Internet is going wild over this problem
9:12
Просмотров 74 тыс.
Ik Heb Aardbeien Gemaakt Van Kip🍓🐔😋
00:41
Subarray with given sum
5:04
Просмотров 193 тыс.
Find missing number from given array
0:59
Просмотров 8 тыс.
Find Missing Number In Array In Java (Hindi)
29:27
Просмотров 83 тыс.
Trick for spiral matrix traversal
10:12
Просмотров 201 тыс.
Largest number formed from an array
8:33
Просмотров 118 тыс.