Frequently Asked Java Program 17: Find Missing Number in an Array

แชร์
ฝัง
  • เผยแพร่เมื่อ 13 ต.ค. 2019
  • Topic : Find Missing Number in an Array
    #########################
    Udemy Courses:
    #########################
    Manual Testing+Agile with Jira Tool
    ************************************
    ► shorturl.at/xNXZ4
    Selenium with Java+Cucumber
    ********************************
    ► shorturl.at/aIKMW
    Selenium with Python & PyTest
    ********************************
    ► shorturl.at/ELW09
    Selenium with python using Robot framework
    ****************************************
    ► shorturl.at/bcDPZ
    API Testing(Postman, RestAssured & SoapUI)
    *****************************************
    ► shorturl.at/uAWY7
    Web & API Automation using Cypress with Javascript
    ********************************************
    ► rb.gy/4uum2n
    Playwright with Javascript
    **************************
    ► shorturl.at/gALZ1
    Jmeter-Performance Testing
    ************************
    ► rb.gy/ocj7r2
    SDET Essencials(Full Stack QA)
    *************************
    ► rb.gy/hlnf2v
    Appium-Mobile Automation Testing
    ************************************
    ► rb.gy/wmzv64
    Java Collections
    *****************
    ► bit.ly/3S66ezE
    Python Programming
    *********************
    ► urlis.net/gdsfpb0s
    Cucumber BDD Framework
    ***************************
    ► bit.ly/3F7d69r
    Protractor with Javascript
    ***************************
    ► urlis.net/4uddm1qb
    ####################################
    TH-cam Playlists:
    ####################################
    Manual Testing & Agile
    ***********************
    ► bit.ly/3ujvaYa
    ► bit.ly/3OYzxQj
    SQL
    *************************
    ► bit.ly/3R6XjeG
    ► bit.ly/3nE0a1s
    ► bit.ly/3IeKuuJ
    linux & Shell Scripting
    **********************
    ► bit.ly/3up1Z6a
    ► bit.ly/3nzvGxx
    Java
    **********************
    ► bit.ly/3R9QfOs
    ► bit.ly/3AoRMKM
    ► bit.ly/3IbTTDn
    ► bit.ly/3ybXInv
    ► bit.ly/3yCoHdw
    Selenium With Java+Cucumber
    ********************************
    ► bit.ly/3P2FMm4
    ► bit.ly/3yhiIt4
    ► bit.ly/3uokzet
    ► bit.ly/3a7XIND
    ► bit.ly/3umN2S9
    ► bit.ly/3aar7GW
    ► bit.ly/3y9kD2S
    ► bit.ly/3uhLskn
    Python
    ********************************
    ► bit.ly/3agNgU0
    ► bit.ly/3NJNnoy
    ► bit.ly/2CTQ4mR
    ► bit.ly/3OIYWh1
    Selenium With Python,Pytest&Behave
    ***************************************
    ► bit.ly/3OHHoC9
    ► bit.ly/3IeNLdv
    ► bit.ly/2J4tPeT
    ► bit.ly/3ydSkAq
    Selenium With Python Using Robert Framework
    (Web&API Testing)
    *************************************************
    ► bit.ly/3nUvlpr
    ► bit.ly/3nUvE3z
    API Testing (Postman,SoapUi,&Rest Assured)
    **********************************************
    ► bit.ly/3OXacWY
    ► bit.ly/3yh0UhE
    ► bit.ly/3nC9DWQ
    ► bit.ly/3yGfhNS
    ► bit.ly/3OJa11H
    ► bit.ly/3P2slCC
    Mobile App Testing Appium
    ****************************
    ► bit.ly/3Al49HG
    Performance Testing Jmeter
    *******************************
    ► bit.ly/3nz4fE7
    Maven,Jenkins,Git,Github,CI/CD
    *******************************
    ► bit.ly/3P16HPj
    ► bit.ly/3yhlUVA
    ► bit.ly/3afYfwT
    ► bit.ly/3yGzweG
    ► bit.ly/3yF73Ws
    ► bit.ly/3NCOmH7
    SQL,DB Testing&ETL,Bigdata
    *******************************
    ► bit.ly/3NKOcNY
    ► bit.ly/3OVpDyI
    ► bit.ly/3NEvUy0
    ► bit.ly/3IryxlT
    ► bit.ly/3RkWBLh
    JavaScript Based Automation Tools
    ********************************
    ► bit.ly/3nUx51X
    ► bit.ly/3AqI6Q0
    ► bit.ly/3yeurbT
    ► bit.ly/3ujzpTK
    Selector Hub Tools
    ********************
    ►rb.gy/h3h424
    GraphQL
    ******************
    ► rb.gy/sj3gys
    Cypress API Testing
    ********************
    ► shorturl.at/fjKPX
    Cypress Web Testing
    **********************
    ► shorturl.at/agjlK
    Playwright with Javascipt
    **************************
    ► shorturl.at/adSTY
    #MissingNumberPython
    #ArrayMissingElement
    #PythonArrayPuzzle
    #ArrayManipulation
    #NumberSearchChallenge
    #CodingPuzzle
    #PythonPuzzleSolving
    #AlgorithmsInPython
    #ArrayManipulation
    #PythonProgramming
    #TechInterviewPrep
    #DataStructures
    #PythonArrays
    #AlgorithmicPuzzle
    #CodingInPython
    #MissingNumberChallenge
    #ArrayProblemSolving
    #LogicPuzzle
    #CodingPractice
    #TechInterviews
    #ProblemSolvingPython
    #ArrayAlgorithm
    #PythonCodeChallenge
    #LogicalThinking
    #ProgrammingPuzzle
    #ArrayManipulation
    #CodingProblems
    #PythonAlgorithms
    #ArraySearch
    #CodeLogic
    #PythonPuzzles
    #MissingNumberArray
    #AlgorithmExploration
    #PythonCodingChallenge
    #ArrayLogic
    #TechPuzzles
    #ProblemSolvingInPython
    #AlgorithmicThinking
    #PythonArrayChallenge
    #PuzzleSolving
    #CodingMindTeasers
    #LogicChallenge
    #PythonAlgorithmExploration
    #ArrayPuzzle
    #CodeOptimization
    #ProgrammingLogic
    #BrainTeasers
    #PythonTechInterview
    #ArrayCode
    #CodeBreaker

ความคิดเห็น • 70

  • @AmanRaj-kc1uu
    @AmanRaj-kc1uu 9 หลายเดือนก่อน

    appreciation for ur efforts that u put in this series

  • @mayurahire2599
    @mayurahire2599 2 ปีที่แล้ว +14

    if you don`t no how elements are given you will follow this code also --->
    public static void main(String[] args) {
    int a[]= {10,11,13,14,15,16,17};
    int sum1=0,sum2=0;
    for(int i=0;i

    • @harshadagothankar965
      @harshadagothankar965 ปีที่แล้ว +1

      to get correct result of sum2, array needs to be in sorted order

    • @mayurahire2599
      @mayurahire2599 ปีที่แล้ว

      @@harshadagothankar965 yes

    • @msgudaduramath4980
      @msgudaduramath4980 ปีที่แล้ว

      I think here we should know the last element also

    • @msgudaduramath4980
      @msgudaduramath4980 ปีที่แล้ว

      And I think instead of doing -->i++ in sum2,first we do like int x=a[1]-a[0];
      Then in sum2 we can do like -->i+x;
      It can help when sorted order is like [2,4,6,8]

    • @msgudaduramath4980
      @msgudaduramath4980 ปีที่แล้ว

      Is it write or wrong bro because I am so confusing here

  • @user-vl8nc8xg5g
    @user-vl8nc8xg5g ปีที่แล้ว +2

    Sum of numbers you can do this way .... n*n+1/2

  • @mathiyalagan.p4250
    @mathiyalagan.p4250 2 ปีที่แล้ว +3

    line 27
    for(int i=1;i

  • @rightatfirst53
    @rightatfirst53 27 วันที่ผ่านมา

    Sir why so complicated, use int c=arr[0] and compare using for loop for arr[i] with c++ values, if mismatch then missing.. please Let me know on this

  • @Arshad_Nawaz2526
    @Arshad_Nawaz2526 หลายเดือนก่อน +1

    Very very simpl explanation ❤

    • @sdetpavan
      @sdetpavan  หลายเดือนก่อน

      Thanks

  • @nileshpardeshi7068
    @nileshpardeshi7068 4 ปีที่แล้ว +26

    How can we calculate if two numbers are missing?

    • @durgaprasadmajji8057
      @durgaprasadmajji8057 2 ปีที่แล้ว

      I have also the same dought. Could you possible to write the code for that.

    • @ninosalkaton4461
      @ninosalkaton4461 2 ปีที่แล้ว

      int arr[] = { 15 ,6 , 7, 10, 11, 13 };

      System.out.println("array without sort: "+Arrays.toString(arr));

      //sort array ascending
      Arrays.sort(arr);
      System.out.println("array with ascending:"+Arrays.toString(arr));

      //sort array ascending without Arrays.sort(arr)
      // int t1;
      // for(int i=0; i

    • @fero___3005
      @fero___3005 2 ปีที่แล้ว

      I think using binary search algorithm

    • @AmolHiwale123
      @AmolHiwale123 2 ปีที่แล้ว

      By using a foreach loop we can compare all the numbers with another list
      Then we can find n missing numbers

    • @shreyasgowda6074
      @shreyasgowda6074 9 หลายเดือนก่อน

      let arr = [1, 3, 5];
      arr.sort((a,b)=>a-b);
      let result = [];
      for(let i=0;i

  • @teluguoptionbuyers600
    @teluguoptionbuyers600 2 ปีที่แล้ว

    this need to be sorted or use smallest to find the starting number. you made it to start from 1 always.

  • @nikhil7947
    @nikhil7947 ปีที่แล้ว +3

    What to do if multiplie numbers are missing

  • @fedbizdynamicsllc6349
    @fedbizdynamicsllc6349 ปีที่แล้ว +3

    For the missing Element of Array, I have the following code which does not give me the missing number. I think there is something wrong with the condition you stated: public static void main(String[] args) {

    int arr[]= {1,2,3,4,5,7,8,9};

    // steps - sum1 is based on the Index

    int sum1=0;
    for (int i=0; i

    • @ShivamSharma-od3yy
      @ShivamSharma-od3yy ปีที่แล้ว

      For step2 as per your case range will 1 to 9 rather than 5

    • @AmitYadav-nz5if
      @AmitYadav-nz5if 11 หลายเดือนก่อน

      You've given range till 9 in array but in sum2 for loop, you've given range till 5. So missing number will give you -24

    • @Rakhiii000
      @Rakhiii000 6 หลายเดือนก่อน

      The range is wrong

  • @tru5919
    @tru5919 2 หลายเดือนก่อน

    n = a.length + 1
    sum2 = n(n+1)/2;
    return sum2 % sum1;

  • @archismansural5076
    @archismansural5076 3 ปีที่แล้ว +6

    This is very hard-coded. A program should be as flexible as possible.

    • @HarshTV97
      @HarshTV97 2 ปีที่แล้ว +1

      Its for the interviews of freshers.

  • @deepakdubey1453
    @deepakdubey1453 2 ปีที่แล้ว +1

    Thanks Sir ..for this simple approach ..🕺

    • @sdetpavan
      @sdetpavan  ปีที่แล้ว +1

      Keep watching

  • @manikantamutyala2152
    @manikantamutyala2152 ปีที่แล้ว +1

    super explanation sir

  • @ruhishabnam8893
    @ruhishabnam8893 4 ปีที่แล้ว +3

    Sir this program is for 1 missing number..if 2 numbers are missing does it show 2 missing numbers??

    • @ninosalkaton4461
      @ninosalkaton4461 2 ปีที่แล้ว

      int arr[] = { 15 ,6 , 7, 10, 11, 13 };

      System.out.println("array without sort: "+Arrays.toString(arr));

      //sort array ascending
      Arrays.sort(arr);
      System.out.println("array with ascending:"+Arrays.toString(arr));

      //sort array ascending without Arrays.sort(arr)
      // int t1;
      // for(int i=0; i

  • @omkarpatil7057
    @omkarpatil7057 2 ปีที่แล้ว +1

    How to find missing num if numbers are not in sequence (we dont knw range values)and array length is very large?

    • @msgudaduramath4980
      @msgudaduramath4980 ปีที่แล้ว

      To find missing number the array should be in the sorted order and the difference between each element should be same

  • @Mustaq15
    @Mustaq15 10 วันที่ผ่านมา

    what if multiple numbers are missing ? in line like (1,4,5,6,7)

  • @lakshmiprasanna7934
    @lakshmiprasanna7934 8 หลายเดือนก่อน

    The above solution is only for any one value is missing in an array what if multiple values are missing in an array, If any one has the solution for my quiry please respond

  • @softwaretestingbasics5352
    @softwaretestingbasics5352 2 ปีที่แล้ว

    Really it's veryful...but I have qsn..if suppose if the number in odd or even sequence will it work ?

  • @swayamprakashbhuyan2580
    @swayamprakashbhuyan2580 2 ปีที่แล้ว +1

    Commenting for better reach

  • @shaikhirfan2799
    @shaikhirfan2799 2 ปีที่แล้ว

    hello sir if it is depends on user if they type some other numbers. then how can we find the missing numbers? Your logic is only when input is given in the program. please clarify

    • @ninosalkaton4461
      @ninosalkaton4461 2 ปีที่แล้ว

      int arr[] = { 15 ,6 , 7, 10, 11, 13 };

      System.out.println("array without sort: "+Arrays.toString(arr));

      //sort array ascending
      Arrays.sort(arr);
      System.out.println("array with ascending:"+Arrays.toString(arr));

      //sort array ascending without Arrays.sort(arr)
      // int t1;
      // for(int i=0; i

    • @palletimadhu9256
      @palletimadhu9256 ปีที่แล้ว

      I. Have the same doubt?

  • @navjotsingh2457
    @navjotsingh2457 ปีที่แล้ว

    ty

  • @ALdracoyt
    @ALdracoyt 27 วันที่ผ่านมา +1

    what if multiple numbers are missing ?

    • @Mustaq15
      @Mustaq15 10 วันที่ผ่านมา

      package Array;
      import java.util.Arrays;
      public class FindMissingElementInArray {
      public static void main(String[] args) {

      int a[]= {1,4,5,6,3};
      Arrays.sort(a);
      int num=a[0];
      for(int i=0; i

  • @arvinsuryavanshi615
    @arvinsuryavanshi615 ปีที่แล้ว

    Sir.If Array series contains multiple missing numbers.this logic works or not

  • @praveenkumar-dr6de
    @praveenkumar-dr6de 2 ปีที่แล้ว +1

    This is only for one missing number in an array.
    Am I right?

    • @MrRoy69
      @MrRoy69 ปีที่แล้ว

      Yup

  • @mdmuddasirulhassan3322
    @mdmuddasirulhassan3322 2 ปีที่แล้ว

    if there are more than one missing number.how to find them?

    • @ninosalkaton4461
      @ninosalkaton4461 2 ปีที่แล้ว

      int arr[] = { 15 ,6 , 7, 10, 11, 13 };

      System.out.println("array without sort: "+Arrays.toString(arr));

      //sort array ascending
      Arrays.sort(arr);
      System.out.println("array with ascending:"+Arrays.toString(arr));

      //sort array ascending without Arrays.sort(arr)
      // int t1;
      // for(int i=0; i

  • @kvelez
    @kvelez 9 หลายเดือนก่อน

    package javaapplication23;
    import java.util.ArrayList;
    import java.util.Scanner;
    public class JavaApplication23 {
    public static void main(String[] args) {
    int sum = 0, sum2 = 0;
    int[] a = {1,2,3};
    int[] b = {1,2,3,4};

    for (int i = 0; i < a.length; i++){
    sum += a[i];
    }

    for (int i = 0; i < b.length; i++){
    sum2 += b[i];
    }

    System.out.println(Math.abs(sum-sum2));

    }

    }

  • @Ratan_tata_jii
    @Ratan_tata_jii 10 หลายเดือนก่อน

    according to your code input: [8,9,11,12,13] output:10 it will come means i will give 5000.

    • @sdetbyraviteja568
      @sdetbyraviteja568 3 หลายเดือนก่อน

      Obviously it will come bro but while iteration 2nd for loop we have to give I value as 8 and then in the condition section we have to pass stopping range called 13. So final result we will get 10

    • @sdetbyraviteja568
      @sdetbyraviteja568 3 หลายเดือนก่อน

      Give me 5000 thousand bro😂😂😂😂😂 please

  • @user-rx1si3yh5x
    @user-rx1si3yh5x 10 หลายเดือนก่อน

    We can have below solution as well in more simpler
    public class FindMissingNumberInArray {
    public static void main(String[] args) {
    int arr[] = { 1, 2, 3, 4, 5, 6, 8 };
    for (int i = 0; i < arr.length; i++) {
    for (int j = i + 1; j

  • @studymaster255
    @studymaster255 ปีที่แล้ว +1

    //Secound for loop modified
    public class MissingNumberFromArray {
    public static void main(String[] args) {
    //Array should not have duplicates
    //Array no need to be sorted order
    //value should be in range
    int a[]= {11,12,14,15};
    int sum=0;
    for(int value:a)
    {
    sum=sum+value;
    }
    System.out.println("Sum of element in array: "+sum);
    int sum2=0;
    for(int i=a[0];i

    • @sivalib3023
      @sivalib3023 10 หลายเดือนก่อน

      it is fine but what will happen if user gives array as a = {15 , 11 , 14 , 12 } as sir said that array can of any order ?

  • @teluguoptionbuyers600
    @teluguoptionbuyers600 2 ปีที่แล้ว

    package FA_Java_Programs;
    public class ArrayMissingNumber {
    public static void main(String[] args) {
    int[] a= {6,3,4,7};
    int sum=0;
    for(int x:a)
    sum+=x;

    int start=a[0];
    for(int i=0;i

  • @ninosalkaton4461
    @ninosalkaton4461 2 ปีที่แล้ว +2

    for missing numbers:
    int arr[] = { 15 ,6 , 7, 10, 11, 13 };

    System.out.println("array without sort: "+Arrays.toString(arr));

    //sort array ascending
    Arrays.sort(arr);
    System.out.println("array with ascending:"+Arrays.toString(arr));

    //sort array ascending without Arrays.sort(arr)
    // int t1;
    // for(int i=0; i