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
  • Навчання та стиль

КОМЕНТАРІ • 37

  • @ramnisanthsimhadri3161
    @ramnisanthsimhadri3161 6 місяців тому +2

    I did not expect this approach

  • @soumyadipmajumder902
    @soumyadipmajumder902 Рік тому

    Sir you are our inspiration.

  • @someshsahu4638
    @someshsahu4638 Рік тому +3

    This is best free series of DSA and only one in java thankyou sir 🙏🏼

  • @suseelkumarannamraju
    @suseelkumarannamraju 3 роки тому +4

    Nice thought & explanation sir. I tried a brute force approach using Priority queue which I ended up iterating twice. Thank you for the solution.

    • @itsdineshvaryani
      @itsdineshvaryani  3 роки тому +1

      Yeah there are different approaches ... But u have to keep in mind of using extra space ...

  • @payallohana4686
    @payallohana4686 8 місяців тому

    Very helpful

  • @shubhamagarwal1434
    @shubhamagarwal1434 2 роки тому +3

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

  • @vengateshm2122
    @vengateshm2122 3 роки тому

    Very well explained. Thank you!

    • @itsdineshvaryani
      @itsdineshvaryani  3 роки тому

      Welcome !!! I request you to share the course with your friends and colleagues as well !!!

  • @usmanakhtar9155
    @usmanakhtar9155 3 роки тому +1

    Stay blessed sir ..well explained..

  • @programmer519
    @programmer519 4 місяці тому

    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

  • @yacinebenamor3178
    @yacinebenamor3178 Рік тому +1

    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;
    }

    • @__AKASHM
      @__AKASHM Рік тому

      This is also a type of brutefoce approach

  • @durgaprasadgiduthuri6362
    @durgaprasadgiduthuri6362 Рік тому +1

    ♥️♥️♥️

  • @vivekprasad1938
    @vivekprasad1938 Рік тому

    static int msNum(int[] arr) {
    for (int i = 1; i

  • @Guilherme.Melo01
    @Guilherme.Melo01 6 місяців тому

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

  • @ekansh6267
    @ekansh6267 10 місяців тому

    👌👍👍

  • @ahamed.ibrahim
    @ahamed.ibrahim 3 роки тому +2

    🔥

  • @RahulRana-on4je
    @RahulRana-on4je Рік тому

    Sir what if the numbers are in not in the n natural numbers series. They are mixed

  • @yarik83men51
    @yarik83men51 2 роки тому +1

    Super

  • @anantkashyap2087
    @anantkashyap2087 3 роки тому +1

    Sir please make a video on heap sort

  • @rabindradocument8934
    @rabindradocument8934 Рік тому

    It won't work for large numbers present in array

  • @rudramodh8776
    @rudramodh8776 2 роки тому +1

    Hello, Dinesh. I have a question: what if the array is {50, 51, 52, 54, 55}? Then what should be the approach?

    • @talalahmed4019
      @talalahmed4019 2 роки тому +2

      // 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;
      }

  • @shubhamshubham7746
    @shubhamshubham7746 Місяць тому

    what if there is no any missing number sir

  • @godl_disaster611
    @godl_disaster611 Рік тому

    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

  • @saidbifalankeep
    @saidbifalankeep Рік тому

    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;
    }

  • @ascar66
    @ascar66 Рік тому +3

    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;
    }
    }