Find element that appears once | Find missing number | Max Consecutive number of 1's | Arrays Part-3

Sdílet
Vložit
  • čas přidán 2. 07. 2024
  • Notes/C++/Java/Python codes in Step 3.1 of bit.ly/tufA2ZYt
    Find the missing number: takeuforward.org/arrays/find-...
    Maximum Consecutive Ones: takeuforward.org/data-structu...
    Find the number that appears once, and the other numbers twice: takeuforward.org/arrays/find-...
    Problem links.
    Find the missing number: bit.ly/3ZdwAkN
    Maximum Consecutive Ones: bit.ly/3ZFZji5
    Find the number that appears once, and the other numbers twice: bit.ly/3VOlEHp
    We have solved the above problems, and we have gone from brute force and ended with the most optimal solution.
    Full Course: bit.ly/tufA2ZYt
    You can follow me across social media, all my handles are below:
    Linkedin/Instagram/Telegram: linktr.ee/takeUforward
    0:00 Introduction of course
    0:57 Missing Number
    18:16 Code-compiler (Missing Number)
    18:44 Maximum Consecutive number of 1's
    21:06 Code-compiler (Maximum Consecutive number of 1's)
    22:49 Find the number that appear once and other number twice
    36:40 Code-compiler (Find the number that appear once and other number twice)

Komentáře • 475

  • @takeUforward
    @takeUforward  Před rokem +88

    Let's march ahead, and create an unmatchable DSA course! ❤
    Use the problem links in the description.

    • @Vijaykrishnan2000
      @Vijaykrishnan2000 Před rokem +2

      Find the number that appear once and other number twice : (Partially Accepted) needed binary search approach ?

    • @ayushsaurav38
      @ayushsaurav38 Před rokem

      bro u use map in array series and in course series so atleast give a short intro of whatever u r using the course bcz this course is for beginners as u said

    • @PHANTOMWORLD
      @PHANTOMWORLD Před rokem

      @@Vijaykrishnan2000 binary search requires sorting and sorting takes O(nlogn)
      so how it is more optimal ?

    • @subrajeetmaharana
      @subrajeetmaharana Před rokem

      @@PHANTOMWORLD the given array is sorted. No need to sort it.

    • @itsmrcrazy7670
      @itsmrcrazy7670 Před 11 měsíci

      @@Vijaykrishnan2000 bro have you found soloution for this

  • @sharathkumar8338
    @sharathkumar8338 Před rokem +144

    are you planning to put Scaler Academy out of business.?? 😆😆

  • @ariobotgaming
    @ariobotgaming Před 22 dny +3

    In an interview, I personally feel jumping to "better" solution is good, instead of "brute" solution, if "better" exists that is.
    Reasons:
    - I dont think the time constraint allows for us to cycle through all three(brute, better, optimal) in 45min-1hr time window (usually 2-3 questions can be asked).
    - Also brute are confusing at times, as it mostly involves combining many steps at times and the dry run will take time, so will the psuedo code.
    - We must also account the stress of the interview, I don't think I can come up with different version of solutions for a single question without messing up the flow (which might ruin the concentration and cause panic). So I think its better to give a solution that you know it works for sure.

  • @Akash-yr2if
    @Akash-yr2if Před 11 měsíci +17

    Striver shouting top oof voice and these DSA problems are getting slightly one after the other in my head. Thanks Striver

  • @actuallynxiss
    @actuallynxiss Před rokem +20

    I absolutely love your videos man! I understood everything very well. Internship season is gonna start very soon in my college and this helps me a ton!

  • @ParasSharma-mf8or
    @ParasSharma-mf8or Před rokem +58

    0:00 Introduction of course
    0:57 Missing Number
    18:16 Code-compiler (Missing Number)
    18:44 Maximum Consecutive number of 1's
    21:06 Code-compiler (Maximum Consecutive number of 1's)
    22:49 Find the number that appear once and other number twice
    36:40 Code-compiler (Find the number that appear once and other number twice)
    Please please please maintain consistency it's a humble request from the bottom of my heart 🙏🙏.

  • @helloworld2054
    @helloworld2054 Před 11 měsíci +3

    Understood everything, you are one of a kind Striver!

  • @reki7247
    @reki7247 Před rokem +4

    you're the best, man! hats off to you for great teaching and concepts that you elaborate so smoothly, i'm second year btech student and i am so thankful to have found you! ever since you came to my college for techtalk i've been motivated and a fan of yours, keep up the good work!

  • @merlingrace6850
    @merlingrace6850 Před 8 měsíci +7

    You did a great job.... I used to afraid of dsa at first but the day I find your channel, I'll be more confident now to clear dsa rounds . Your hard work deserves a lot Striver. You explanation is crystal clear and it's keep us engaging with each step of concept.

    • @user-oi1oe5he5r
      @user-oi1oe5he5r Před 4 měsíci

      we learn concept but forget again ,bcs there are lots of problems and concepts

  • @AarzooBansal
    @AarzooBansal Před 22 dny

    Thank you for all your videos! You have no idea how much these are helping everyone out there!!

  • @rahulkathayat8542
    @rahulkathayat8542 Před rokem +7

    Love your content striver keep blessing us with such amazing videos

  • @Deena_Bandhu
    @Deena_Bandhu Před rokem +4

    bhaiya its mean a lot for us who can't afford a course...! and providing this level of lectures such a next level....! i will try to be a like you in future so i can help the peoples in other way....! thank you bhaiyya

  • @cinime
    @cinime Před rokem +2

    Understood! Amazing explanation as always, thank you very much for your effort!!

  • @gwatsinthong3180
    @gwatsinthong3180 Před 4 měsíci

    Thank you Sir 🙏 Truly the way you explain is really easy to understand. It is hard to believe such a great man exist that gives such great quality material for free

  • @GB-su9gu
    @GB-su9gu Před rokem +9

    you are real hero for me.
    best teacher
    like done 😊

  • @pranavrakhunde
    @pranavrakhunde Před 10 měsíci +5

    For the last problem Find number that appear once and other twice the below code passes all the 11 test cases
    int getSingleElement(vector &arr){
    int ans = 0;
    for(int i=1;i

    • @user-oi1oe5he5r
      @user-oi1oe5he5r Před 4 měsíci +1

      nice

    • @rudrsharma4758
      @rudrsharma4758 Před měsícem

      that solution is wrong, it won't give correct output for cases like [0, 1, 0, 1, 2]
      in this case at the first iteration for i=1:
      arr[1-1] != arr[1] is true and thus it will return arr[1-1] as output, which is 0, whereas the correct output is clearly 2.

    • @user-kk2pk2cd9c
      @user-kk2pk2cd9c Před měsícem

      @@rudrsharma4758 It is sorted array though.

    • @akshitrajputhere
      @akshitrajputhere Před 25 dny

      Thanks mate this does work

  • @Karthi875
    @Karthi875 Před 11 měsíci +2

    Thankyou striver for your hardwork to make me understand your efforts make me work hard

  • @aashishas7044
    @aashishas7044 Před 10 měsíci

    The video and material were awesome. thanks for your efforts.

  • @jishnuraj2278
    @jishnuraj2278 Před rokem +1

    Understood! Amazing Explanation!

  • @055_meetmakwana9
    @055_meetmakwana9 Před 4 měsíci +2

    Absolutly loved it, for the first problem in this video, I actually tried to solve it on my own, and thought of an solution which turns out to be a optimal solution you metioned here in this video, this is not a small achievement for me😃. Thank you striver.

  • @AJDJ108
    @AJDJ108 Před 8 měsíci

    Understood each concept brother we need this kind of video 🎉

  • @itzmartin20
    @itzmartin20 Před 10 měsíci

    Understood! You make my day again brother!

  • @PrithaMajumder
    @PrithaMajumder Před měsícem +1

    Raj, Thanks a lot for This Amazing Video about C++ Arrays
    Video - 3 Completed ✅

  • @virendrakumarmishra876

    amazing just loved it
    so clear explanation 😍

  • @himadriroy7980
    @himadriroy7980 Před 8 měsíci

    Understood!! Loved the lecture.

  • @john_doe_2231
    @john_doe_2231 Před rokem +16

    Hey Striver , i had a question since you're working in Europe.Do European tech companies also ask a lot of DSA in their interviews or is it more focused towards other topics like design ,LLD etc ? Would really love a video on this .

  • @dhruvsolanki4473
    @dhruvsolanki4473 Před rokem +1

    Super amazing videos and explanations.

  • @Ishantkumar-cr6ug
    @Ishantkumar-cr6ug Před rokem

    understood bhaiya...we need more videoes in a week, and get well soon..

  • @habeeblaimusa4466
    @habeeblaimusa4466 Před rokem

    Thanks for this amazing video..God bless you

  • @saikrishnaganguri
    @saikrishnaganguri Před rokem +1

    Understood, Thank you so much for the awesome content..

  • @varunvarun5723
    @varunvarun5723 Před rokem +1

    Thanks for the amazing content striver

  • @user-fn1lx2gv9j
    @user-fn1lx2gv9j Před rokem +17

    As the input array is already sorted, we can use binary search to find the single element in the array.
    public int singleNonDuplicate(int[] nums) {
    int low = 0;
    int high = nums.length - 1;
    int mid;
    while (low < high) {
    mid = (low + high) / 2;
    if (mid % 2 != 0) {
    mid -= 1;
    }
    if (nums[mid] == nums[mid + 1]) {
    low = mid + 2;
    } else {
    high = mid;
    }
    }
    return nums[low];
    }

  • @ABCDEFGH-fz5ju
    @ABCDEFGH-fz5ju Před 2 měsíci

    His actions while explaining problems are just killer😎

  • @tabrezahmed1000
    @tabrezahmed1000 Před 10 měsíci +4

    Corrected code for missing numbers:
    class Solution {
    public:
    int missingNumber(vector& nums) {
    for(int i = 1; i

  • @SudhanshuPanthri
    @SudhanshuPanthri Před 11 měsíci

    Brilliantly Explained Bhaiya.

  • @utsavseth6573
    @utsavseth6573 Před rokem

    Lovely Work Raj.

  • @shanmugapriya6735
    @shanmugapriya6735 Před rokem

    You are my lifesaver thank you so much sir

  • @konankikeerthi
    @konankikeerthi Před měsícem

    Thank you bro. i got clear understanding. i understood it very well

  • @monimoni6760
    @monimoni6760 Před rokem +2

    Hi Striver,
    Thanks for your effort.When will you be covering strings and Heap.I am not able to see any video related to that topic in your channel.

  • @kavyabanka4482
    @kavyabanka4482 Před rokem

    Thanks for this amazing video

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

    AWESOME EXPLANATION

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

    understood bhaiyaaa thankyou for the great explaination

  • @sukhpreetsingh5200
    @sukhpreetsingh5200 Před rokem

    As usual awesome ❤

  • @aliakbaransaria3-925
    @aliakbaransaria3-925 Před 10 měsíci

    Very good explanation

  • @peddikarthik7832
    @peddikarthik7832 Před 11 měsíci +1

    one slight correction at 17:23 : xor can exceed largest number.(ie when number n%4==2)

  • @rish7394
    @rish7394 Před rokem +1

    Bhaiya kasam se din se so rkha tha🥲, abhi socha kya kru notification aagya thanks.

  • @vishal_s583
    @vishal_s583 Před rokem

    Great work ❤️

  • @shivangisirohi6032
    @shivangisirohi6032 Před 6 měsíci

    great explanation sir

  • @suheabkhan2546
    @suheabkhan2546 Před rokem

    Loved the content

  • @sohamchikane6591
    @sohamchikane6591 Před 10 měsíci +1

    gaining confidence day by day one question though when should we revise?
    any suggestions would be appreciated.

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

    Understood, thankyou bhaiya

  • @hareshnayak7302
    @hareshnayak7302 Před 3 měsíci

    Understood, thanks striver.

  • @Ramsiya658
    @Ramsiya658 Před rokem

    Understood striver much love to you

  • @DevashishJose
    @DevashishJose Před rokem

    Understood, Thank you

  • @rohitprasad5708
    @rohitprasad5708 Před rokem +5

    Bro can you please take some time out from your busy schedule and upload a detailed video on Java collection framework, and can you please let us know what all core skills required for being a Java developer apart from DSA.
    Thanks

    • @aadeshputhran7642
      @aadeshputhran7642 Před rokem +1

      You can watch this detailed Java collections tutorial: czcams.com/video/VE_AAUxTUCY/video.html&ab_channel=RiddhiDutta

  • @Mythri333
    @Mythri333 Před 4 měsíci

    Thank you so much 😊

  • @shorts_shots514
    @shorts_shots514 Před rokem

    understood !!! thank you

  • @Raj10185
    @Raj10185 Před rokem

    Understood everything Striver :)

  • @sarangkumarsingh7901
    @sarangkumarsingh7901 Před 3 měsíci

    Awesome Sir.............

  • @DeveloperRB
    @DeveloperRB Před 8 měsíci

    Great stuff ❤❤

  • @themusicguy539
    @themusicguy539 Před rokem +2

    Hello sir
    Thankyou for your efforts
    I have a question sometimes I make the approach of a question but not able to code it...maybe lack of doing questions by myself
    But just when I was doing questions of binary search of rotated sorted array of your DSA sheet...I am neither able to make approach nor code it....any guidance... (4th semester student)

  • @_hulk748
    @_hulk748 Před rokem

    Understood sir❤🙇‍♂️🙏

  • @shreyanshsharma7906
    @shreyanshsharma7906 Před rokem

    understood thanks raj bhai

  • @khushil9988
    @khushil9988 Před 7 měsíci

    understood
    and yes we need the video

  • @divyaagarwal3563
    @divyaagarwal3563 Před rokem

    UNDERSTOOD!

  • @fallenAngel-cw9ki
    @fallenAngel-cw9ki Před rokem

    understood, ty!!

  • @aadeshputhran7642
    @aadeshputhran7642 Před rokem +2

    For the number that appears once problem, if the input array is sorted, I think the optimal time complexity will be O(log n) using binary search.

    • @takeUforward
      @takeUforward  Před rokem +4

      Yes if it is sorted, here it was not

    • @user-ll9py8pq2u
      @user-ll9py8pq2u Před 6 měsíci

      how can i solve this question using binary search

    • @jaydeeppatil7936
      @jaydeeppatil7936 Před 6 měsíci

      @@user-ll9py8pq2u did you manage to solve it using binary search

  • @Hipfire786
    @Hipfire786 Před 2 měsíci

    understood everything sir

  • @moviesinthelist6551
    @moviesinthelist6551 Před 10 měsíci

    @takeUforward at 16:40, I think even we are running the first statement in second loop to avoid the first loop still the complexity going to be O(2n) because we increase the no. of statement executing

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

      that's not how it works

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

      @@anshumann ohh I thought every line of code or every task takes one unit of time

  • @faysalmahmud2721
    @faysalmahmud2721 Před 11 měsíci

    best explaination

  • @codesetter2497
    @codesetter2497 Před dnem +1

    When I see question my mind works in finding directly the optimal solution after reading question 2 things came in my mind that I have to use no extra space like first try to solve it without extra space then in O(N) or in O(log n) possible
    and after speeding some couple of minutes I directly finds the optimal solution
    So I don't have idea about what will the brute force in this case or better

  • @ankushladani496
    @ankushladani496 Před rokem

    Understood
    More videos....🎉

  • @foreverabel7680
    @foreverabel7680 Před 10 měsíci

    understood sir 🙌

  • @Sanjana-gp3gn
    @Sanjana-gp3gn Před 11 měsíci

    Understood bhaiya ❤

  • @RaviKumar-sn6tu
    @RaviKumar-sn6tu Před 4 měsíci

    sir you have my heart
    😇

  • @lifehustlers164
    @lifehustlers164 Před 9 měsíci +1

    Completed 3/28!!!

  • @shashank_0807
    @shashank_0807 Před 2 měsíci

    Whenever your heart is broken
    Don't ever forget you're golden ❤✨
    The happiness when you hear these lines at the end of each video >>>>>>>>>>>>>>>>>> ♾

  • @ajaywankhade5054
    @ajaywankhade5054 Před měsícem

    Thank you

  • @sysybaba420
    @sysybaba420 Před 5 měsíci

    @26:50, why do you need a for loop to look for the largest element? the input array is already sorted so the last element will always be the largest no?

  • @gkfactsandquiz3056
    @gkfactsandquiz3056 Před rokem +5

    For the question find the number that appear once we can also use 2(n(n+1)/2 ) - sum of elements in array
    Note : n is the maximum element in the given array
    Because we know that all the other numbers are twice
    Hope it is helpful 😊
    And thank you striver for the awesome explanation

    • @KeepCoding69
      @KeepCoding69 Před 11 měsíci +2

      No, it won't work. If we consider the array 4,1,2,1,2, the answer should be 4, but if we follow your formula, the result is 10, which is incorrect.

    • @gkfactsandquiz3056
      @gkfactsandquiz3056 Před 11 měsíci +1

      @@KeepCoding69 this formula works only if the numbers are consecutive and in the question if they mention only consecutive numbers are given as input it will definitely works 🙂

    • @gkfactsandquiz3056
      @gkfactsandquiz3056 Před 11 měsíci

      @@KeepCoding69 try with consecutive numbers input like 3,1,2,1,2

  • @karnifex7606
    @karnifex7606 Před 11 měsíci

    missing number with one variable(more simplified)
    int res = N;
    for(int i=0; i

  • @sahilranjan324
    @sahilranjan324 Před rokem

    Bhaiyaa Thanks 😊👍

  • @mehrasmotivation6970
    @mehrasmotivation6970 Před rokem

    Thank you bhaiya SDE sheet ke questions karane ke liye

  • @Miracle_shaw
    @Miracle_shaw Před rokem

    thank you

  • @ultimategamer5136
    @ultimategamer5136 Před rokem

    Can anyone explain Why use outer loop as i

    • @takeUforward
      @takeUforward  Před rokem

      the size of the array is N-1, and not N, as one number is missing, read the question

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

    Understood✅🔥🔥

  • @yashwanthbm7543
    @yashwanthbm7543 Před rokem

    THANKS BRO

  • @jashanuppal9678
    @jashanuppal9678 Před 4 měsíci

    @takeUfoward I had one doubt, in missing number like what if the the last number is missing then the XOR logic will not work because it nums.size will itself be 1 less already so it will not work that case?

  • @impalash_ag
    @impalash_ag Před měsícem

    Hi @takeUforward, 2 questions on Missing Number problem:
    1- Does the Brute Force solution has to be same as yours? For instance, I thought of sorting the array first and then check each element with index+1, and as soon as we find the missing element we return with index+1. The TC of the overall algorithm will be 0(nlogn){for sorting} + 0(n){for traversing}
    2- What if we can't think of any better solution and miss explaining that to an interviewer? For instance, in my case I could think of the above and summation of n natural numbers solutions only.
    I hope you address the questions and reply, thank you 😊

  • @amanallrounder2092
    @amanallrounder2092 Před 22 dny

    1st optimal solution was really good and new for me 09:00

  • @Alwaysalearner123
    @Alwaysalearner123 Před 6 měsíci

    If the array range is [0,n] In Missing no problem for brute approach for loop should be this for(int i=0;i

  • @s_sattu_s
    @s_sattu_s Před 3 měsíci

    Here's my most optimal code for the last question using XOR :
    class Solution {
    public:
    int singleNumber(vector& nums) {
    int ans = 0;

    for(int i=0; i

  • @heyOrca2711
    @heyOrca2711 Před 3 měsíci

    Understood sir!

  • @user-tk2vg5jt3l
    @user-tk2vg5jt3l Před 5 měsíci

    Thank you Bhaiya

  • @AsharMallick750
    @AsharMallick750 Před rokem

    Thanks striver bro

  • @ROCKY-tq1we
    @ROCKY-tq1we Před 4 měsíci +4

    For the missing number problem we can use index to compare the elements:
    for ( int i = 0 ; i < n ; i++)
    {
    if ( arr[i] ! = i+1 )
    {
    return i;
    }
    }

    • @dbhanuprakash515
      @dbhanuprakash515 Před 4 měsíci +6

      This will not applicable if array is not in sorted order ❤

    • @chennupalliharish7126
      @chennupalliharish7126 Před 3 měsíci

      just use sum of n natural numbers formula and take all the sum into a varaible .Subtract each element from sum with all the array element and return the end sum

    • @prafulsharma462
      @prafulsharma462 Před 2 měsíci

      I don't get why he is iterating 1st for loop in missing number
      From 0 to =n it will give an exception
      If some one know pls tell
      One more thing
      In 2nd loop why 0 to n-1

    • @aakash_jamadar939
      @aakash_jamadar939 Před 2 měsíci

      It won't work.
      take A=[1,1,2,2,3] and check

    • @aakash_jamadar939
      @aakash_jamadar939 Před 2 měsíci

      @@prafulsharma462 we don't do arr[i] for first loop,we use only numbers(i) in this loop.so we used range of numbers present in the array(i,e 1 to n).
      for 2nd loop,we need arr[j],so we use 0 to

  • @lostcyrus8578
    @lostcyrus8578 Před rokem +1

    Consistency 🔥🔥

  • @pujyamvssnkdheeraj5069
    @pujyamvssnkdheeraj5069 Před 9 měsíci +1

    Bro A small Doubt - In Finding The Number that appears once, you took the max element by using a Loop - TC - O( n ) & a hash iterator - TC- O(n) ,:- TC - O( 3n )
    > Insted [ My Logic ]
    - If Array is Always Sorted can we take array [ n-1] as MAX so tha t we do not need to iterate the Entire hashing we can iterate up to max value we can make it - TC - O( 2n ) & SC - O ( n )

  • @AayushDubey_007
    @AayushDubey_007 Před rokem +2

    Please solve for GFG question - " Given a binary array arr of size N and an integer M. Find the maximum number of consecutive 1's produced by flipping at most M 0's." whose link is given on ur website .
    Please do solve GFG question links too as they r different from Code Studio ones .

    • @eshanberry7186
      @eshanberry7186 Před 10 měsíci

      bro that is the medium one it requires bit manipulation concept in gfg that why i left and done in the leetcode

  • @parthkandwal8343
    @parthkandwal8343 Před rokem

    Understood Sir