Find the Missing Number in an Array | Animation | Coding Interview Question
Вставка
- Опубліковано 10 лип 2021
- ►Full DSA Course - • Data Structures and Al...
►Follow me on Instagram - bit.ly/intrvwkckstrt
►Follow me on LinkedIn - bit.ly/fllwlkdn
►Enroll in the complete course: bit.ly/3W4qthg
►Source Code - github.com/dinesh-varyani/ds-...
►Download DSA Animation Slides - techready.in/courses/150-dsa-...
►Click here to subscribe - ua-cam.com/users/hubbersp...
Watch all my playlist here:
►Data Structures and Algorithms Course playlist: • Data Structures and Al...
►Mastering JUnit 5 - ua-cam.com/users/playlist?list...
►Mastering Mockito 3 - • Mockito 3 Tutorials
►Analysis of Algorithms - • Analysis of Algorithms
►Linked List Data Structures - • Linked List Data Struc...
►Array Data Structures - • Playlist
►Stack Data Structure - • Stack Data Structure
►Queue Data Structure - • Queue Data Structure
►Binary Tree Data Structure - • Binary Tree Data Struc...
►Graph Data Structure - • Graph Data Structure
►Binary Heap Data Structure - • Binary Heap Data Struc...
►Trie Data Structure - • Trie Data Structure
►Dynamic Programming Algorithms - • Dynamic Programming Al...
►Hashing Data Structures - • Hashing Data Structures
►Sorting and Searching - • Sorting and Searching
►String Algorithms - • String Algorithms
Want to land a software engineering job in the IT industry? This course - 'Visualizing Data Structures and Algorithms' is here to help. The course walks you through multiple Java algorithms, data structures problems, and their solutions with step by step visualizations, so that you are actually learning instead of blindly memorizing solutions.
The course covers in and outs of Data Structures and Algorithms in Java. Java is used as the programming language in the course. Students familiar with Javascript, Python, C#, C++, C, etc will also get to learn concepts without any difficulty. The implementation of various Algorithms and Data Structures have been demonstrated and implemented through animated slides. It covers many interview room questions on Algorithms and Data Structures. The questions and solutions are demonstrated by -
1. Animated slide. (To make visualization of algorithms faster)
2. Coding algorithm on IDE.
The course covers topics such as -
0. Algorithm Analysis
1. Arrays
2. Matrix
3. Singly Linked List
4. Doubly Linked List
5. Circular Singly Linked List
6. Stacks
7. Queues
8. Binary Tree
9. Binary Search Tree
10. Graphs
11. Priority Queues and Heaps
12. Recursion
13. Searching
14. Sorting
15. Strings
16. Trie Data Structure
17. Dynamic Programming
and many more ...
#dsa #algorithms #coding - Навчання та стиль
I did not expect this approach
Sir you are our inspiration.
This is best free series of DSA and only one in java thankyou sir 🙏🏼
Welcome
Nice thought & explanation sir. I tried a brute force approach using Priority queue which I ended up iterating twice. Thank you for the solution.
Yeah there are different approaches ... But u have to keep in mind of using extra space ...
Very helpful
Best series for DS & Algo. I am also 10 yrs java exp guy. Was looking for DS & Algo free course over UA-cam with java implementation and found this. Hats Off To You Man....Excellent Work. GOD BLESS YOU :)
Thanks !!!
@@itsdineshvaryani bot
Very well explained. Thank you!
Welcome !!! I request you to share the course with your friends and colleagues as well !!!
Stay blessed sir ..well explained..
Thanks !!!
It seems like increasing the length of the array to arr.length + 1 may lead to errors, as in the case of [3,0,1], where the expected output is 2, but it would yield 6. Since we are only returning the sum and not the array itself, increasing the length doesn't seem necessary. Thankyou
My alternative solution
public static int findMissing(int[] array) {
int missing = 1;
int i = 0;
while(i < array.length) {
if(array[i] == missing) {
missing++;
i = 0;
} else {
i++;
}
}
return missing;
}
This is also a type of brutefoce approach
♥️♥️♥️
static int msNum(int[] arr) {
for (int i = 1; i
this is O(n^2), nested for loop dear
Sr. Dinesh, first of all, thanks a lot for this content! Why in some cases we've to use 'int n = arr.length' instead of 'int n = arr.length+1' Do you have any tip? hug from Brazil!!
👌👍👍
🔥
Thanks !!!
Sir what if the numbers are in not in the n natural numbers series. They are mixed
Super
Thanks !!!
Sir please make a video on heap sort
Sure !!!
It won't work for large numbers present in array
Hello, Dinesh. I have a question: what if the array is {50, 51, 52, 54, 55}? Then what should be the approach?
// Arithmetic Progression
// lastNumb = firstNumber + (totalNumbersInAP - 1)(differenceBetweenNumbers)
// a_last = a_first + (n - 1)d
// sum =(n/2)(2a+(n-1)d)
private static int findMissingNum(int[] arr) {
Arrays.sort(arr);
int minNum = arr[0];
int n = arr.length + 1;
//assuming diff between numbers = 1
int sum = (n/2)*((2*minNum) + (n-1));
for (int num : arr){
sum = sum - num;
}
return sum;
}
what if there is no any missing number sir
XOR APPROACH
class Solution {
public int missingNumber(int[] nums) {
int i , X = 0, Y = 0 ;
for(i = 0 ; i < nums.length ; i++){
X ^= nums[i];
}
for(i = 1 ; i
my custom algo;
public static int endArr(int[] arr){
int start = arr[0];
for(int i = 0 ; i < arr.length ; i++){
if(start < arr[i]){
start = arr[i];
}
}
return start;
}
public static int startArr(int[] arr){
int start = arr[0];
for(int i = 0 ; i < arr.length ; i++){
if(start > arr[i]){
start = arr[i];
}
}
return start;
}
public static int findMissingNumber(int [] arr,int start, int end){
boolean IsFind=true;
int missingN=0;
for(int i = start ; i < end ; i++){
for(int j = 0 ; j < arr.length ; j++){
if(i == arr[j]){
IsFind = true;
break;
}
else{
IsFind = false;
}
}
if(!IsFind){
missingN = i;
}
}
return missingN;
}
Sir why don't just do n*(n+1)/2 - sum? I mean we can find the sum of a given array and then minus the sum from n(n+1)/2
public class Main {
public static void main(String[] args) {
int[] array = new int[] {2, 4, 1, 8, 6, 3, 7};
System.out.println(missingNumber(array));
}
private static int missingNumber(int[] array) {
int n = array.length + 1;
int sum = Arrays.stream(array).sum();
return n * (n + 1)/2 - sum;
}
}