Find Missing and Duplicate Number in an Array | Swap Sort Need

Sdílet
Vložit
  • čas přidán 28. 08. 2020
  • Patreon Link: / adityaverma
    Video Pdf Notes And Code: / 40985869
    Playlist Link: • Find missing and dupli...
    Problem Description: www.interviewbit.com/problems...
    Given an unsorted array of size n. Array elements are in the range from 1 to n. One number from set {1, 2, …n} is missing and one number occurs twice in the array. Find these two numbers in order of one space.
    Input:[3 1 2 5 3]
    Output:[3, 4]
    Duplicate = 3, Missing = 4 .
    ------------------------------------------------------------------------------------------
    Here are some of the gears that I use almost everyday:
    🖊️ : My Pen (Used in videos too): amzn.to/38fKSM1
    👨🏻‍💻 : My Apple Macbook pro: amzn.to/3w8iZh6
    💻 : My gaming laptop: amzn.to/3yjcn23
    📱 : My Ipad: amzn.to/39yEMGS
    ✏️ : My Apple Pencil: amzn.to/3kMnKYf
    🎧 : My Headphones: amzn.to/3kMOzM7
    💺 : My Chair: amzn.to/385weqR
    🛋 : My Table: amzn.to/3kMohtd
    ⏰ : My Clock: amzn.to/3slFUV3
    🙋🏻‍♀️ : My girlfriend: amzn.to/3M6zLDK ¯\_(ツ)_/¯
    PS: While having good gears help you perform efficiently, don’t get under the impression that they will make you successful without any hard work.

Komentáře • 130

  • @TheAdityaVerma
    @TheAdityaVerma  Před 3 lety +63

    In the next video we will see how swap sort could really reduce all these efforts and can really make this easy. I mean really easy !

    • @sandeepm2723
      @sandeepm2723 Před 3 lety

      DP God es playlist main sare interview bit ke question solve karwa do it will help a lot to prepare for interviews pls.

    • @rishukasoudhan2736
      @rishukasoudhan2736 Před 3 lety

      we can also solve by xor???

    • @akshatagrawal2690
      @akshatagrawal2690 Před 3 lety

      @@rishukasoudhan2736 how please explain

    • @aKnightTraveller
      @aKnightTraveller Před 2 lety

      @Akshat Agarwal
      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

    • @programmer545
      @programmer545 Před rokem

      bhai chinese bandey ki link dedo blogs ki😅

  • @RohitKulkarni0810
    @RohitKulkarni0810 Před 3 lety +16

    Dude, if it weren't for you, I'd still be crying over how tough DP and Recursion is. I've only been binge watching all your videos for the past 2 weeks for prep . Thanks a lot man for doing what you do. Helped me out a ton!

  • @rudraksh9635
    @rudraksh9635 Před 3 lety +36

    Finally , see who is back now 😌
    bruhhh please add backtracking and greedy algorithms too !!

  • @sohilmomin575
    @sohilmomin575 Před 3 lety +10

    After waiting for very long time. Finally we have legend back to serve best in the history.

  • @muskantrisal5355
    @muskantrisal5355 Před 3 lety +6

    Itna wait to corona ki vaccine ke lie bhi nhi hai, jitna in videos ke lie tha😍😍😍. Thank you!!😍

  • @sayandeepghosh2911
    @sayandeepghosh2911 Před 3 lety +20

    You helped me to be good in dynamic programming....thank you for helping this community....I always used to do top down approach but bottom up is best way to solve dp problems❤️❤️🔥🔥

  • @D4arkl0rd
    @D4arkl0rd Před 3 lety +2

    Solution toh bahut log bataate hain, lekin samjhaane ka hunar har kissi mein nahin hota. Good going boy, you'll be a name to reckon someday.

  • @nobita7933
    @nobita7933 Před 3 lety +2

    Oh brooo.. ..just loved it.. Thank you ❤

  • @bhatanand
    @bhatanand Před 2 lety +3

    You can use a bitmap to do this without swap sort. Set the bit for every number found. If the bit is already set, then its a duplicate number. If some bits are unset, then they are missing.

  • @akhilk5121
    @akhilk5121 Před 3 lety +2

    Yes!!! My fav algo teacher is back😎😀

  • @divyachoudhary5938
    @divyachoudhary5938 Před 3 lety +1

    Someone is back after a long wait........ Badly waited for ur videos 😀

  • @sahilpahuja
    @sahilpahuja Před 3 lety +8

    Simple solution from my side: Use a for loop and match array elements with iterator(i) and if it's a mismatch then i is missing no and element at ith position is repeated element... But it will only work for single missing and duplicate element

    • @komaldeepsingh6356
      @komaldeepsingh6356 Před 3 lety +1

      array will not be sorted.. in video he has taken a sorted array but you can check qt on geeksforgeeks...this array is nto sorted

  • @saurabhsaraswat4362
    @saurabhsaraswat4362 Před 3 lety +2

    Again great video by great man 🔥🔥

  • @saurabhgupta4082
    @saurabhgupta4082 Před 3 lety

    Finally sir aap aa hi gye.Ab kuch acha seekhne ko milega

  • @sidhantchandak5152
    @sidhantchandak5152 Před 3 lety +2

    PLEASE daily videos upload karna, and abhi placements chal rhi, please try to make videos on grapshs. You made me fall in love with CP. Thank you so much

  • @jayshree9037
    @jayshree9037 Před 3 lety +3

    Thanks for the new playlist, reducing time and space on spot in interviews is really overwhelming🙊

    • @frobenius7080
      @frobenius7080 Před 3 lety

      Jay Shree has a crush on aditya

    • @jayshree9037
      @jayshree9037 Před 3 lety +5

      @@frobenius7080 har jagah same comment q krre ho bhai.
      Thoda apni zindagi v sawar lo

    • @frobenius7080
      @frobenius7080 Před 3 lety

      @@jayshree9037 Sorry. You opened my eyes

    • @frobenius7080
      @frobenius7080 Před 3 lety +3

      It's OK Mai apni Zindagi sawar lunga , But please accept that you have a crush on aditya 😂😂

  • @udaypandey5659
    @udaypandey5659 Před rokem +2

    java - solution for Math example : please use Biginteger data type to stop intgerOverflow
    public class FindMissingAndDuplicate_SC1 {
    public static void main(String[] args) {
    int[] arr = { 4, 3, 2, 6, 5, 5 };
    findMisssingAndDuplicate(arr);
    }
    private static void findMisssingAndDuplicate(int[] arr) {
    int n = arr.length;
    int sum_n = (n * (n + 1)) / 2;
    int sum_nSq = ((n * (n + 1)) * 2 * n + 1) / 6;


    for (int x : arr) {

    sum_n-= x; // sum(1 to N) - sum (array)
    sum_nSq-= x *x ; // sum (1 square to N square ) - sum ( square of each element in array)

    }

    int missingNumber = (sum_n +(sum_nSq/sum_n))/2;
    int duplicareNumber = missingNumber - sum_n;

    System.out.println("misssingNumber "+missingNumber);
    System.out.println("duplicateNumber "+duplicareNumber);


    }
    }

  • @rishabsharma5307
    @rishabsharma5307 Před 3 lety +2

    Thanks for upgrading your mic now we can hear your voice more clearly

  • @baaznotapro5479
    @baaznotapro5479 Před 3 lety

    Itni khusi... Itni khusi aaj tak nahi hui

  • @AmanKumar-ht8xi
    @AmanKumar-ht8xi Před 3 lety

    Kya mast chij h bey poora system hila deta h 😂❤️

  • @devendrasingh4776
    @devendrasingh4776 Před 3 lety +4

    Bro please make videos on graph and segmemt trees . Please your channel is growing fast . Hope u understand our needs too. Thank you by the way for this video

  • @shivambaghel9668
    @shivambaghel9668 Před 3 lety +5

    I think,we can also use enumerate function (in python) in which we check if (i+1!=item) then i+1 will be the missing number and arr[i] will be the duplicate number
    It also give us time complexity-O(n) and space complexity-O(1)

    • @komaldeepsingh6356
      @komaldeepsingh6356 Před 3 lety +1

      array will not be sorted.. in video he has taken a sorted array but you can check qt on geeksforgeeks...this array is nto sorted

  • @arindamsarkar5543
    @arindamsarkar5543 Před 3 lety +4

    Thanks for these videos bro. Any plans to complete the remaining dp videos?

  • @ViralAgrawal12321
    @ViralAgrawal12321 Před 3 lety +1

    Finally new video...came....

  • @sohilmomin575
    @sohilmomin575 Před 3 lety +11

    Ise pakad le rakho kahi he wapas bhag na jaye😅 want heart...

    • @TheAdityaVerma
      @TheAdityaVerma  Před 3 lety +2

      ❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️

    • @TheAdityaVerma
      @TheAdityaVerma  Před 3 lety +5

      🏃🏻‍♂️💨💨💨💨💨💨💨

  • @kapilchoudhary2922
    @kapilchoudhary2922 Před 3 lety +4

    Finally after a loooong time, the lord is back into the arena. Welcome boss!! #veer_bahadur

  • @savin1999
    @savin1999 Před 3 lety +2

    Sir, can you make some videos on-grid problems that are generally asked in coding rounds?

  • @princegarg1086
    @princegarg1086 Před 3 lety +1

    Anyone can please recommend me any resources to learn about pointers because when I try to implement dsa based on pointes implementation I stuck at that point @Aditya Verma

  • @goforshahriar
    @goforshahriar Před 3 lety +1

    graph and tree topic will be helpful

  • @trywithsky
    @trywithsky Před rokem

    man it was very cool!

  • @samakshtak9859
    @samakshtak9859 Před 3 lety +2

    Great content but also need Graphs And Tree related vids

  • @AmitSangwan123
    @AmitSangwan123 Před 3 lety

    very helpful

  • @anmolsingh9084
    @anmolsingh9084 Před 3 lety +5

    Sir I was someone always running from coding but i recently completed your recursion series and m like always thinking about ways to solve problems whole day in back on my mind. Sir, just wanted to ask if you can take out a small amount of time and let me know the way to see your playlist as m confused which one to see first or in which order..
    Lots of love and support from Sonepat.

    • @TheAdityaVerma
      @TheAdityaVerma  Před 3 lety +8

      You can start with any series tbh, all series are independent, but dont skip any video in a playlist once you start, start with Recursion, cuz thats my fav 😅❤️

    • @anmolsingh9084
      @anmolsingh9084 Před 3 lety

      @@TheAdityaVerma I literally love you to make a soo called cse student fall in love with coding. Today i completed the recursion series and started watching dp.
      Although, Hope to get your insta id.
      loll ;-)

  • @ritikarai1232
    @ritikarai1232 Před 3 lety

    thank u:)

  • @krishnendughosh2368
    @krishnendughosh2368 Před rokem +1

    Ou boi...that's pure math.

  • @shashidharreddy8529
    @shashidharreddy8529 Před 3 lety +6

    we can solve this without swap sort.
    using Counter in python in O(1),bro please check this following code:
    from collections import Counter
    n=10
    a=[1,2,2,5,5,4,6,9,9]
    for i in range(1,n+1):
    a.append(i)
    x=Counter(a)
    miss=[]
    dupi=[]
    for i in x:
    if x[i]==1:
    miss.append(i)
    elif(x[i]>2):
    dupi.append(i)
    print("missing = ",miss)
    print("Duplicate = ",dupi)

    • @TheAdityaVerma
      @TheAdityaVerma  Před 3 lety +8

      I am not well versed in python, but by the looks of it, counter does what map does in cpp right? So you are using extra space, but the whole idea was to avoid using extra space. I discussed that in some earlier videos of the series.

  • @mrsukki8158
    @mrsukki8158 Před 3 lety +1

    Writing on paper is best we get more concentration

  • @ViralAgrawal12321
    @ViralAgrawal12321 Před 3 lety +3

    Sound quality improved a lot

    • @TheAdityaVerma
      @TheAdityaVerma  Před 3 lety +2

      haha Thanks, glad you noticed !

    • @ViralAgrawal12321
      @ViralAgrawal12321 Před 3 lety +2

      @@TheAdityaVerma offcourse u are teahing method is so grear everyone just waits for your video....please bhiaya make more and more videos jaan laga ke promote karega apun...aapko...🙏💯

    • @TheAdityaVerma
      @TheAdityaVerma  Před 3 lety +3

      ❤️❤️ Thanks brother

  • @user-gd8wg6dr5t
    @user-gd8wg6dr5t Před rokem

    On patrean do we need to buy notes.

  • @anshita6898
    @anshita6898 Před 3 lety +1

    Sir.. Plzzz make vdeos of graph and backtracking

  • @ViralAgrawal12321
    @ViralAgrawal12321 Před 3 lety +2

    Bhaiya which series is this...please make a series on graphs and backtracking please......

  • @harshitanand8216
    @harshitanand8216 Před 3 lety +3

    Congratulations for getting job in Flipkart. 🎉🥳

  • @ewananmo2404
    @ewananmo2404 Před 2 lety

    Supa hot fire!

  • @princegarg1086
    @princegarg1086 Před 3 lety +2

    Khaa thyee bhai 😉🧐 wait kra dia bhut

    • @TheAdityaVerma
      @TheAdityaVerma  Před 3 lety

      Ab shuagat ni kroge hmara 😛

    • @ViralAgrawal12321
      @ViralAgrawal12321 Před 3 lety

      @@TheAdityaVerma 50 toppo ki salami se sawagt kiya jata hai DP gawddd ka....

    • @ShaileshKumar-kk7nt
      @ShaileshKumar-kk7nt Před 3 lety

      @@TheAdityaVerma Aapke aane ki khusi me hi swagat kiya gaya hai aapka itne saare comments se by the community, hope u liked it.

    • @princegarg1086
      @princegarg1086 Před 3 lety

      Swaagtm swaagtm swaagtm bhaiya or kuch chaiye bhaiya swagat mein bta dyna comments kr dugaa 🙏🙋‍♂️🙏

    • @TheAdityaVerma
      @TheAdityaVerma  Před 3 lety +1

      haha bs bs bhai Thanks you all, kaafi swagat ho gya 😅🙏🙏🙏🙏🙏🙏

  • @ankitsrivastava5961
    @ankitsrivastava5961 Před 3 lety

    finally firse kuch acha seekhenge

  • @saurabhgupta4082
    @saurabhgupta4082 Před 3 lety

    Bhai please jaldi se backtarcking graphs cover krdo campus placements start ho gyi hai .Aur jab tak ye topics nhi ho jaate ache se mujhe confidence nhi ayega.

  • @youtubeuserlovesyoutube2207
    @youtubeuserlovesyoutube2207 Před 9 měsíci

    bro we should have mutliplied all elements of array , then taken gcd n-1 factorial and multiplied value , then divided gcd by both number , one should have missing number and other repeated number.

  • @khushiagrawal6537
    @khushiagrawal6537 Před 3 lety +3

    More videos please!

    • @TheAdityaVerma
      @TheAdityaVerma  Před 3 lety +3

      Yup, there will be more !

    • @raviashwin1157
      @raviashwin1157 Před 3 lety +1

      @@TheAdityaVerma bhai aajkal bandiyon ko reply de rahe ho bando ko nahi kya chakkar hain?

    • @TheAdityaVerma
      @TheAdityaVerma  Před 3 lety +4

      @bro ravi, जाकी रही भावना जैसी,प्रभु मूरत देखी तिन तैसी।😂

    • @TheAdityaVerma
      @TheAdityaVerma  Před 3 lety +4

      bhai aesa ni upr niche dekho sbke reply kiye, jitni der b online tha ✌️❤️

    • @raviashwin1157
      @raviashwin1157 Před 3 lety +3

      @@TheAdityaVerma Here is the meaning -जाकी रही भावना जैसी, प्रभु मूरत देखी तिन तैसी..... रामचरितमानस
      जिनकी निंदा-आलोचना करने की आदत हो गई है, दोष ढूंढने की आदत पड़ गई है, वे हज़ारों गुण होने पर भी दोष ढूंढ लेते हैं और जिनकी गुणग्रहण की प्रकृति है, वे हज़ार अवगुण होने पर भी गुण देख लेते हैं, क्योंकि दुनिया में ऐसी कोई भी चीज नहीं है, जो पूरी तरह सर्वगुण संपन्न हो या पूरी तरह गुणहीन हो. एक न एक गुण या अवगुण सभी में होते हैं. मात्र ग्रहणता की बात है कि आप क्या ग्रहण करते हैं, गुण या अवगुण? तुलसीदास जी ने भी कहा है, जाकी रही भावना जैसी, प्रभु मूरत देखी तिन तैसी. अर्थात जिसकी जैसी दृष्टि होती है, उसे वैसी ही मूरत नज़र आती है.

  • @Animax590
    @Animax590 Před 3 lety +1

    sir plz add more videos on any topic . It seems you gone ;(

  • @krishnaprasad3350
    @krishnaprasad3350 Před 3 lety +2

    Swagat bhai!

  • @aakashKumbhare
    @aakashKumbhare Před 2 lety

    Can you give the blog link of that Chinese guy

  • @ghoshdipan
    @ghoshdipan Před 3 lety

    Bro please 1 video sliding window pe bana diyo. Bahut confusion lgta hai yehh walaa problem.

  • @raunak1786
    @raunak1786 Před 3 lety

    Queues and Trees playlist please

  • @no-body7286
    @no-body7286 Před 3 lety

    sir chinese banda blog link please

  • @063harshsahu2
    @063harshsahu2 Před rokem

    can anyone share code for this method

  • @baaznotapro5479
    @baaznotapro5479 Před 3 lety

    Phir se underground to nahi ho jayega na.. plzzz we really need you

  • @ashishkumarmaurya2371
    @ashishkumarmaurya2371 Před 3 lety +4

    Bhai 8 minutes 300 views baval kat rhe......
    Aapko bhi ab apne CZcams channel pe dhyan dena chahiye.......
    You are next aman dhatarwall ......
    Vo bolke motivate karta hai....
    Aap karke ....... You are legend

    • @nobita7933
      @nobita7933 Před 3 lety

      Aman dhattarwal is love bhai ❤

    • @TheAdityaVerma
      @TheAdityaVerma  Před 3 lety +1

      Thanks brother ❤️ Really this comment mean a lot ❤️ Will definitely improve !

    • @ashishkumarmaurya2371
      @ashishkumarmaurya2371 Před 3 lety +1

      Bhai please graph ...
      Bhai tumhe dp ne famous kiya because aaj tak CZcams pe koe ni jo aapke jaise contant de ske...
      So please graph k sath bhi yahi hai......sabhi ne hauva bana rakha hai...ki graph hard hai...
      Aapko address karna chahiye.......
      Baki aapki mazi......

    • @TheAdityaVerma
      @TheAdityaVerma  Před 3 lety +5

      Ha brother ik, but good things take time, i dont want it to be just another graph series on youtube.

    • @ashishkumarmaurya2371
      @ashishkumarmaurya2371 Před 3 lety +1

      @@TheAdityaVerma Shi hai aapki marzi..... But but most of us graph hi chahate hai.....
      Bhai ak bar aap graph khatm kar le phir...... Dekhata khatm hote hote 1 lack subscriber ho jayenge I'm damm sure.... Phir uske bad to aap keval coding hi ni guide bhi kijiye hmm logon ko aapki jarurat hai.....
      Jo banda coding me creative hai....
      Vo life me kitna creative hoga....
      Apne experience ko share kijiye....
      Believe kariye..... Vo jyada aapko help karega....... Aur hmme bhi
      Ye mat sochiye ki graph jaise topic khatm ho jayega to phir kuchh bachega ni....aaisa ni hai...... Balki aapko to phir ak bahot badi audience mil jayegi..... Jise phir keval padhana hi ni use guide bhi karna aapki jimmedari ho jayegi......

  • @abhinavmishra7617
    @abhinavmishra7617 Před 3 lety

    algi video jldi lao....agli video jldi lao.....agli video jldi lao.....please bhai.

  • @tg62672
    @tg62672 Před 2 lety

    i guess this can be solved this using floyd's cycle detection

  • @DMDRPBHU
    @DMDRPBHU Před 3 lety +3

    Flipkart se order ki tha book abhi tak nahi aya thoda dekhar batai

  • @kherakshay7854
    @kherakshay7854 Před 3 lety

    Bhai graph ke questions dalo please

  • @063harshsahu2
    @063harshsahu2 Před rokem

    anyone Send me code for this

  • @aayush5474
    @aayush5474 Před 3 lety

    jaldi jaldi ye video khatam krunga toh turant doosra video dekhunga.

  • @gregoryv7597
    @gregoryv7597 Před 3 lety +1

    Gaon vaalo...Dekho Vo aa gaya

  • @adityaagrawal4878
    @adityaagrawal4878 Před 3 lety

    jaldi dalo swap sort

  • @ankitsrivastava2929
    @ankitsrivastava2929 Před 3 lety +1

    what about counting sort

  • @sahllsaharn4664
    @sahllsaharn4664 Před rokem

    Maine kiya tha prr nhi hua

  • @amitatiwari9103
    @amitatiwari9103 Před 3 lety

    Heyy Aditya !! Where are you from?

  • @nikhilpandey856
    @nikhilpandey856 Před 3 lety

    Bhai Backtracking kab?????????????????????
    Please jaldi.....

  • @shashwatchawla
    @shashwatchawla Před rokem +1

    // code
    class Solution {
    public:
    vector findErrorNums(vector& nums) {

    int missing;
    int duplicate;
    long long n = nums.size();

    long long sumofn = (n*(n+1))/2;

    long long arraysum=0 ;
    for(int i=0;i