Find missing number in an array

preview_player
Показать описание
This video shows three techniques on how to find the missing number in an array. The techniques are based on hashing, sum formula and XOR. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)
Рекомендации по теме
Комментарии
Автор

Great video ! 🙌 I understand the XOR operation by this video.

deepjyotidebnath
Автор

Great video ! 🙌 No need to research the best approach just watch your videos and you are good to go ! Thanks🙌🙌

dikshakatake
Автор

mast vide thi, sare methods samajh aa gye. Thanq.

killeraloo
Автор

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

nitin-
Автор

Thank you sir, Just one question that how can I build my mind to think for the solution in such various approaches

aaditpalande
Автор

If the given array is sorted, then binary search can be applied ( logn) time

Firstusee
Автор

Sort the array then

For(int i=0;i<n;i++)
if(arr[i]!=i+1)
printf("%d", i+1);

divakarkumar
Автор

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).

iamnimish
Автор

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

Cloud-
Автор

sir very good explain thankyou sir ji

rajukumar-svvj
Автор

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 <= n + 1; i++) {
x2 = x2 ^ i;
}
return x1 ^ x2;

}

public static void main(String[] args) {

int[] a = { -1, 1, 2, 3, 4, 5, 6, 7 };

int n = a.length;
int missing = missingNumber(a, n);
System.out.println(" Missing Number is ::: " + missing);

}

}

ashuiet
Автор

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.

rashibansal
Автор

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]]

mujahidpasha
Автор

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

cb
Автор

Sir, kindly explain what is overflow for this case.

FANSasFRIENDS
Автор

use binary search, time complexity will be logN

dineshverma-inon
Автор

Can you please share the code of the third approach?

har.preet.singh.
Автор

n*(n+1)/2 - sum of array elements
Will also work 😄🍻

kartikbhanderi
Автор

As well as please explain code for the problem.

kommunagasheshu
Автор

Sir, what about the time it takes to make the second array(the complete one)?

natnaelghirma