Reverse Pairs | Hard Interview Question

Поделиться
HTML-код
  • Опубликовано: 29 янв 2025

Комментарии • 230

  • @abhishekverma7604
    @abhishekverma7604 Год назад +138

    i have been asked this question in my intuit online assesement for an intern role...
    and i know how inversion count principal works..so i did it comfortably..
    but that too only bcoz of old video of striver....
    thanks bhya ..love u

  • @junaid61747
    @junaid61747 7 месяцев назад +18

    The amount of clarity you have over concepts is truly remarkable! Hope to be as good as you one day.

  • @shubhamagarwal1434
    @shubhamagarwal1434 5 месяцев назад +16

    #Free Education For All.. # Bhishma Pitamah of DSA...You could have earned in lacs by putting it as paid couses on udamey or any other elaerning portals, but you decided to make it free...it requires a greate sacrifice and a feeling of giving back to community, there might be very few peope in world who does this...."विद्या का दान ही सर्वोत्तम दान होता है" Hats Off to you man, Salute from 10+ yrs exp guy from BLR, India.

  • @nirupamsuraj1634
    @nirupamsuraj1634 Год назад +70

    Those people wondering why cant we just multiply a 2 in the count inversion logic. Because if we compare with twice the values, the array doesnot end up being sorted in each iteration, which will contradict our assumption. Try yourselves with different testcase, you will get it.

    • @HarshKumar-ip5nr
      @HarshKumar-ip5nr Год назад +5

      Where I am missing, can you pin point with example
      class Solution {
      private:
      int count=0;
      void merge( vector &nums, int start, int mid, int end){
      vector temp;
      int i=start; int j=mid+1;
      while( i

    • @nirupamsuraj1634
      @nirupamsuraj1634 Год назад +2

      @@HarshKumar-ip5nr bro try not doing temp.pushback inside nums[i] >2*nums[j]. It is not the logic for sorting. nums[i] >2*nums[j] should be handled inside another while loop seperately, and just increase your count there and nothing else. Keep the while loops for sorting as it is in merge sort.

    • @nirupamsuraj1634
      @nirupamsuraj1634 Год назад +1

      ​@@HarshKumar-ip5nr Try referring this python code
      def merge(nums,l,m,r,count):
      arr1 = nums[l:m+1]
      arr2 = nums[m+1:r+1]
      n1 = len(arr1)
      n2 = len(arr2)
      i,j,k = 0,0,l
      ptr1,ptr2 = 0,0

      while ptr1

    • @puneetnj
      @puneetnj Год назад +2

      Thanks Nirupam!!

    • @manvendrasingh4369
      @manvendrasingh4369 7 месяцев назад +2

      But I have not changed the original logic of merge sort but I write this new logic separately inside that else in if-else. So can any one tell me why it is still wrong because now it is not disturbing sorting.
      okay I got it

  • @ravishkumar6060
    @ravishkumar6060 Год назад +11

    The energy with you explain the problem and it's solution is really amazing Sir!!!
    Your teaching methodology is so simple and convincing that even if you make 1-2hr video for a problem, I can watch it with 100% attention...

  • @AdityaSharma-er3gs
    @AdityaSharma-er3gs 6 месяцев назад +6

    25:09 Here you can also use
    private static int countPairs(int[] nums, int s, int m, int e){
    int i = s;
    int j = m+1;
    int count = 0;
    while(i

    • @12anikeshguhaxa5
      @12anikeshguhaxa5 2 месяца назад

      i was also using this logic but no this doesnt work ...maybe i am doing something wrong

    • @ictfan-ly8gh
      @ictfan-ly8gh Месяц назад

      It is better.

  • @mysticlunala8020
    @mysticlunala8020 6 дней назад +1

    It's similar to inversion of array question. Just change
    arr[i] > arr[j] to arr[i]/2 > arr[j] and you are done. Same Complexity

  • @mehulthuletiya497
    @mehulthuletiya497 Год назад +9

    00:40 Problem Statement
    00:59 Explanation
    02:58 Brute-force approach
    03:03 Intuition
    03:28 Pseudocode
    04:21 Complexity
    04:55 Optimal solution
    05:22 Intuition
    14:20 Approach + Dry-run
    22:06 Pseudocode
    25:16 Code
    29:16 Complexity

  • @sohilpathan9006
    @sohilpathan9006 Год назад +49

    In Leetcode it will give buffer overflow because int can't store 2x value of INT_MAX So u can use
    nums[i] > (long long)2*nums[right]
    OR
    0.5*nums[i] > nums[right]
    any one of them in while loop condition in countPairs.

    • @shashanktripathi6277
      @shashanktripathi6277 Год назад

      use typecasting

    • @wttc4
      @wttc4 Год назад +2

      or you can do like this also: nums[i] > 2LL * nums[right]. (we're comparing int to long long)
      To be more safe, do this: 1LL * nums[i] > 2LL * nums[right]

    • @shivanshpatel1898
      @shivanshpatel1898 11 месяцев назад

      @@wttc4 this worked and code is submitted but can you please explain how it works

    • @wttc4
      @wttc4 11 месяцев назад +2

      @@shivanshpatel1898 simply 2 means 2 is int, whereas 2LL means 2 is of type long long.
      1LL * nums[i] means we are multiplying long long and int, so 1LL * nums[i] is of type long long.
      Similarly, in some cases, you can also do 0LL + some_int to make the type of result to long long.

    • @lakshsinghania
      @lakshsinghania 8 месяцев назад

      @@wttc4 so basically the whole multiplication is taking place in long long i assume right ?

  • @namanchandak1532
    @namanchandak1532 Год назад +11

    here is more optimized code
    you also should apply binary search in the counting pair function instead of increasing right because right portion of the array is sorted
    int countP(vector& nums, int l, int m, int h)
    {
    long long int right=m+1,cnt=0;
    for(int i=l;i

    • @sunny_23561
      @sunny_23561 7 месяцев назад

      yup... ease this using upper bound

    • @yashwanthyerra2820
      @yashwanthyerra2820 2 месяца назад

      But it is taking more time to execute than this
      class Solution {
      private int countAndMerge(int[] nums, int left, int mid, int right) {
      int count = 0;
      int j = mid + 1;
      for (int i = left; i

  • @cinime
    @cinime Год назад +7

    Understood! Another super amazing explanation as always, thank you so so SO much for your effort!!

  • @SHASHANKRUSTAGII
    @SHASHANKRUSTAGII Год назад +20

    i did this question during my placement prep and yes i saw with my naked eyes how we can make use of merge sort and in general count inversion in nlogn time :)
    Good work striver!

  • @mdzaidhassan426
    @mdzaidhassan426 5 месяцев назад

    Your effort in making us understand the whole approach is commendable! Thanks a lot :)

  • @vineetjadhav1785
    @vineetjadhav1785 16 дней назад

    Crystal Clear Explaination Understood in one GO ❤️🥇💯

  • @juhichoudhary9281
    @juhichoudhary9281 Год назад +1

    Understood, You are The Best Striver

  • @shyampawar8893
    @shyampawar8893 5 месяцев назад +1

    Perfectly Explained and Best series

  • @neerajkumar-ts6om
    @neerajkumar-ts6om 5 месяцев назад

    Thanks bhai maja aya question solve krke, pata nhi kaise batau kitna maza aarha hai code karke abb.

  • @aafilburner
    @aafilburner Год назад +10

    a[i] > 2* a[right] condition may cause overflow...
    rewrite as 0.5 * a[i] > a[right]

    • @saisri5953
      @saisri5953 Год назад

      thanks

    • @harshjha1616
      @harshjha1616 Год назад

      it worked thanks

    • @SairamSudiReddy
      @SairamSudiReddy Год назад +1

      or cast 2*a[right] to long

    • @YN__YN
      @YN__YN Год назад

      thanks a lot

    • @wttc4
      @wttc4 Год назад +1

      or you can do like this also: nums[i] > 2LL * nums[right]. (we're comparing int to long long)
      To be more safe, do this: 1LL * nums[i] > 2LL * nums[right]

  • @jeeveshkumar9682
    @jeeveshkumar9682 7 месяцев назад

    i thought of sorting the whole array and then using two pointers to compare the values and increase the count accordingly. But the problem with this solution is that the constraint of keeping i

    • @shikher4559
      @shikher4559 5 месяцев назад

      are you talking about thIs solution ?
      public int merge(int[] arr, int low, int mid, int high){
      int left = low;
      int right = mid+1;
      int pairs = 0;
      ArrayList temp = new ArrayList();
      while(left

    • @btechstudent1620
      @btechstudent1620 5 месяцев назад

      @@shikher4559 yes is this working ?

    • @shikher4559
      @shikher4559 5 месяцев назад

      @@btechstudent1620 its working with a bit modification
      1) run a loop for calculating pairs separately
      2) do the same as this code

    • @078_garlapatilikhitreddy8
      @078_garlapatilikhitreddy8 5 месяцев назад +1

      ​@@shikher4559counting the pairs seperately is fine i thought while merging we can modify the count as with counting inversion. After doing a dry run i understood that I have count the pairs seperately and then do the merging

  • @055_meetmakwana9
    @055_meetmakwana9 9 месяцев назад

    Understood, You are The Best Man!

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 Год назад +1

    Understood your previous explanation and current explanation both are good

  • @ksankethkumar7223
    @ksankethkumar7223 Год назад +14

    Toughest problem understood as a piece of cake..

  • @code99-masters
    @code99-masters Месяц назад

    truly understand , nicely explained

  • @RohitKumar-dy2gc
    @RohitKumar-dy2gc 7 месяцев назад

    thankyou for such a wonderful explanation striver✨✨

  • @ShahNawaz-cx3pi
    @ShahNawaz-cx3pi 6 месяцев назад +2

    Count Pair function can also be implemented as:-
    int CountPairs(vector&arr,int low,int mid, int high){
    int i = low;
    int j = mid+1;
    int cnt = 0;
    while(i

    • @abhinavraj6507
      @abhinavraj6507 5 месяцев назад

      Did your code get accepted ?

    • @shaikhmoin849
      @shaikhmoin849 4 месяца назад

      @@abhinavraj6507 yes this will work.

  • @nirmalm80
    @nirmalm80 6 дней назад

    Great Explanation

  • @kavyahegade6477
    @kavyahegade6477 7 месяцев назад +2

    whle comparing, if one element from 2nd array does not form a pair with an element in 1st array, you said you will miss out the next element. but in reality we do not. because we increment the 1st array i des and check again, if it works then all other works, so count inversion algorithm works

    • @mohdnabeel702
      @mohdnabeel702 7 месяцев назад +1

      In count inversion we are trying to find the smaller number suppose we are at 6 and 3, we see 3 is smaller, we add 3 to our answer list, and increment the right pointer to compare next pointer with 6, missing out on comparing 3 with the next elements in left array. (this is how I understood).

    • @harim7945
      @harim7945 Месяц назад

      i got the same doubt!!!!
      did u get clarity?

    • @mriduljain1981
      @mriduljain1981 12 дней назад

      @@mohdnabeel702 nope thats not right , if 6 is not greater than twice of3 we increment "i" which means for 13 we will check if 3 could be a possible value so we are not missing out on any case ig

  • @kaichang8186
    @kaichang8186 4 месяца назад

    understood, thanks for the great explanation

  • @vikasbagri1225
    @vikasbagri1225 Год назад

    Understood it very well
    Thanks for this amazing video

  • @akshaygill4692
    @akshaygill4692 Год назад +6

    can someone explain why the if condition i put in else block would not work here
    while(left

    • @shivasai7707
      @shivasai7707 Год назад +1

      yes i have the same doubt it should work i felt i was the only one

    • @kishore4262
      @kishore4262 Год назад

      Can someone explain this.Thanks in advance:)

    • @mohdnabeel702
      @mohdnabeel702 Год назад

      Same thing we just have to modify the if condition rather than doing arr[i]>arr[j] Iam using arr[i] > 2*arr[j]; Both are getting accepted.

    • @mohdnabeel702
      @mohdnabeel702 Год назад

      @@shivasai7707 It works
      import java.util.ArrayList;
      class Solution {
      public int reversePairs(int[] nums) {

      return mergeSort(nums,0,nums.length-1);
      }
      public static int mergeSort(int[] arr,int lo, int hi){

      if(lo >= hi)
      return 0;
      int mid = (lo + hi)/ 2;
      int counter=mergeSort(arr,lo,mid);
      counter+=mergeSort(arr,mid+1,hi);
      counter+=countPairs(arr,lo,mid,hi);
      merge(arr,lo,mid,hi);
      return counter;
      }
      public static void merge(int []arr,int lo,int mid,int hi){
      List tempList = new ArrayList();
      int i = lo;
      int j = mid+1;
      while(i

    • @kishore4262
      @kishore4262 Год назад

      Hey @@mohdnabeel702 ;
      can you explain me whats wrong with this:
      class Solution {
      public:
      void merge(vector &nums,int low,int mid,int high,int &c){
      int i = low;
      int j = mid+1;
      vector temp;
      while(i

  • @narasimhann2814
    @narasimhann2814 Год назад +1

    Can someone tell why the below fails. It clears 33 TC but not all. Its a modification to no of inversion pair where for each element in right I find the left array range to satisfy the condition
    int merge(vector&arr, int start,int mid,int end){
    int n1 = mid-start+1;
    int n2 = end-mid;
    int i,j,x;
    long long count=0;
    vector a1(n1);
    vector a2(n2);

    for(x=0,i=start; i

  • @iamnoob7593
    @iamnoob7593 Месяц назад

    got it , Striver thank you

  • @242deepak
    @242deepak Год назад +4

    Easier way:
    class Solution {
    public:
    int merge(int l,int mid,int r,vector &nums) {
    vector temp;
    int i=l,j=mid+1,count=0;
    while(i

    • @abhijeettripathi7615
      @abhijeettripathi7615 Год назад

      actually that should be the way it will have analogy between count inverison and this

  • @studynewthings1727
    @studynewthings1727 Год назад

    Awesome explanation.

  • @paneercheeseparatha
    @paneercheeseparatha 5 месяцев назад +1

    Amazing guy!

  • @torishi82
    @torishi82 6 месяцев назад

    Amazing. Thank you.

  • @praveensoni1119
    @praveensoni1119 11 месяцев назад

    Can't thank you enough Man!!

  • @Manishgupta200
    @Manishgupta200 Год назад +1

    According to me, it's a medium level question... because I understood clear concept of mergeSort by your tutorial. Thankyou Striver

  • @inspiringzone12
    @inspiringzone12 Год назад +1

    Great explanation

  • @AjaySaini-hc9ho
    @AjaySaini-hc9ho 11 месяцев назад

    Thanks brother!❤

  • @YourCodeVerse
    @YourCodeVerse Год назад

    Understood✅🔥🔥

  • @avijeetswain7101
    @avijeetswain7101 Год назад +2

    25:00 can somebody help me please? Here we are using a zero index array so when we are doing (right -(mid+1)) can't we write it as (right-(mid+2)) we also did in count inversion (mid -(left+1)).
    Or (right-(mid+1)) means how far right is from its initial position mid+1 ??

    • @S.s-tz9fo
      @S.s-tz9fo Год назад +3

      the right pointer stops at one place greater , we are adding total number of elements before the right pointer(excluding right)

    • @avijeetswain7101
      @avijeetswain7101 Год назад +1

      Thanx brother

  • @suheabkhan2546
    @suheabkhan2546 Год назад

    Great explanation.. understood.... Why is the notes for the previous videos , are linked to old articles.. will the new articles replace them or new articles will not be written for them?

    • @takeUforward
      @takeUforward  Год назад

      The articles are new, if you go though them, they are updated... We did not create a new article, instead updated the older ones.

  • @cricketobserver178
    @cricketobserver178 Год назад +7

    Medium questions are a combination of two easy questions
    And hard questions are combination of two medium problems
    That's my observation till now

  • @venup2813
    @venup2813 11 месяцев назад

    understood striver💥

  • @Appcgubn
    @Appcgubn 8 месяцев назад

    why cant we use treemap and traverse through the array and store the occurences of the number and checking them upto the condition verifies in the tree map

  • @ErenYeager-dp4er
    @ErenYeager-dp4er 21 день назад

    Done on 9 Jan 2025 at 12:02
    Place : Study Room 2 , Hotel 5, IIT Bombay

  • @vikashH-h1v
    @vikashH-h1v 4 месяца назад

    int countPairs(vector &arr, int low, int mid, int high) {
    int right = mid + 1;
    int cnt = 0;
    for (int i = low; i

  • @AdityaSingh-uy8ms
    @AdityaSingh-uy8ms 4 месяца назад

    UNDERSTOOD !!

  • @umangsharma7364
    @umangsharma7364 5 месяцев назад

    Wondering if we can solve this through TreeSet

  • @harshilpatel3205
    @harshilpatel3205 5 месяцев назад

    Understood 🙏🏻

  • @aniketkhorwal7289
    @aniketkhorwal7289 10 месяцев назад

    thanks striver💙

  • @iamxpossible
    @iamxpossible 4 месяца назад

    use long long to avoid integer overflow!

  • @gyanendrasaurav877
    @gyanendrasaurav877 Год назад

    (mid+1)-i will also work just fine but keep that inside the while loop

  • @nikhilchobhiyal
    @nikhilchobhiyal 5 месяцев назад

    Maamaamiyaa!!!

  • @shubha_jagadeesh
    @shubha_jagadeesh 3 месяца назад

    understood 💗

  • @TasneemMohammad-oj3ie
    @TasneemMohammad-oj3ie 2 дня назад

    cpp code if u want it..
    dont know why the inside loop counting didnt works u need a new loop itseems
    code:
    class Solution {
    public:
    int merge(vector& nums , int low ,int mid, int high){
    vector temp;
    int left = low;
    int right = mid+1;
    int cnt = 0;
    // new loop only for counting
    for(int i=low;i

  • @AmanSingh-yc4cw
    @AmanSingh-yc4cw 10 месяцев назад

    Understood 👍

  • @jeetoppers3150
    @jeetoppers3150 9 месяцев назад

    understood
    😍😍😍😍😍

  • @anshulrai6058
    @anshulrai6058 3 месяца назад

    understood👍

  • @____priyanka_b_
    @____priyanka_b_ Год назад

    Can you please explain same codes in java

  • @akilesh6379
    @akilesh6379 4 месяца назад +1

    understood sir

  • @bhagyashri863
    @bhagyashri863 Год назад

    understoood🤩

  • @akshayvakharia7552
    @akshayvakharia7552 9 месяцев назад

    Hi @takeUForward
    UNDERSTOOD.
    But can we align with the previous solution by tricking a bit like
    else {
    //For this question condition change
    int tempPointer = leftPointer;
    while (tempPointer (2 * input[rightPointer]))) {
    tempPointer++;
    }
    if (input[tempPointer] > (2 * input[rightPointer])) {
    count += (mid - tempPointer + 1);
    }

    // Existing Merge code
    list.add(input[rightPointer]);
    rightPointer++;
    }

  • @priyotoshsahaThePowerOf23
    @priyotoshsahaThePowerOf23 9 месяцев назад

    In leet code its taking 232 MB ..means temp arr taking extra spaces right striver??

  • @reassume4826
    @reassume4826 Год назад

    I dont get why do we need to put this function before merge method? When I am putting in merge method, it gives wrong answer. Can anyone point out why? I put this logic before actual merge operation inside merge function, still giving wrong answer.

  • @AppaniMadhavi
    @AppaniMadhavi Год назад

    Superb

  • @HoneySingh-yp7zc
    @HoneySingh-yp7zc 8 месяцев назад

    superb

  • @karthikarthik1795
    @karthikarthik1795 Год назад

    Sir it is also showing time limit exeeded error

  • @akshatverma8086
    @akshatverma8086 Год назад +1

    Hey @striver , recently I started doing ur a2z DSA sheet. After learning array from ur playlist I am doing string but the problem I am able to solve the questions even medium level. What approach should I apply. I give 20 mins to understanding n more and then code. It gives results 60%but not 💯. How should I start?

  • @shivasai7707
    @shivasai7707 Год назад +6

    im totally confused if 6 is greater than twice of 2 then 13 21 25 will be greater than twice of 2 as they are greater count of inversions method should work
    striver please help thanks:)

    • @nirupamsuraj1634
      @nirupamsuraj1634 Год назад

      Because if we compare with twice the values, the array doesnot end up being sorted in each iteration, which will contradict our assumption.

    • @abhijeettripathi7615
      @abhijeettripathi7615 Год назад

      your code will work correct thought process

    • @nirupamsuraj1634
      @nirupamsuraj1634 Год назад +4

      @@abhijeettripathi7615 the code will work as long as you seperate the counting logic from sorting logic. In sorting logic dont compare with twice the values.

  • @Subiksha-hc2vv
    @Subiksha-hc2vv 7 дней назад

    why cnt is not added with merge...In counting pairs cnt is added with merge..but here its not..why

  • @shashvatsinghal2574
    @shashvatsinghal2574 6 месяцев назад

    I did this using a multiset, got a time complexity of O(3nlogn) but still i got tle
    "class Solution {
    public:
    int reversePairs(vector& nums) {
    multiset ms;
    for(auto i:nums) ms.insert(i);
    long long final=0;
    for(int i=nums.size()-1;i>=0;i--){
    auto it=ms.find(nums[i]);
    ms.erase(it);
    auto lb = ms.lower_bound((2 * (long long)nums[i])+1);
    final += distance(lb, ms.end());
    }
    return final;
    }
    };"

  • @akashsingh9301
    @akashsingh9301 Год назад

    THANKU BHAI

  • @kamleshverma9724
    @kamleshverma9724 Год назад

    will this code work for already sorted array??
    because for sorted array, every left element will be smaller than element in right/right array???

    • @OrderEmperor
      @OrderEmperor Год назад +2

      😂😂there will be no pair in that case so obviously count will be 0

  • @hemantpatel1413
    @hemantpatel1413 7 месяцев назад

    Understood.

  • @PriyaSharma-v8u
    @PriyaSharma-v8u Год назад

    Understood!

  • @AmanKumarSinhaOfficial
    @AmanKumarSinhaOfficial Год назад +2

    Please make an {Android App Development} course

    • @takeUforward
      @takeUforward  Год назад +9

      I am a full stack dev, I have no experience in it 😅

    • @tapansonak1431
      @tapansonak1431 Год назад +9

      @@takeUforward Please make a full stack web dev course

    • @lakshsinghania
      @lakshsinghania 8 месяцев назад

      @@tapansonak1431 There are diff courses on yt watch out that for instance hitesh choudhary, and some foreign yt channels/ udemy courses which are good

  • @culeforever5408
    @culeforever5408 Год назад +1

    understood :)

  • @DeadPoolx1712
    @DeadPoolx1712 5 месяцев назад

    UNDERSTOOD;

  • @AbjSir
    @AbjSir Год назад

    understood

  • @m.rnaganathan7492
    @m.rnaganathan7492 Год назад

    how to show all the pairs can you help me out or anyone pls

  • @vibhutijoshi07
    @vibhutijoshi07 2 месяца назад

    cant we do this using map?

  • @mriduljain1981
    @mriduljain1981 12 дней назад

    count inversion logic is working fine whats wrong with this function
    int i = low;
    int j = mid+1;
    while(i

  • @saillaanil6948
    @saillaanil6948 Год назад +1

    can anyone please help me, why this code is not working
    int merge(vector &arr, int low, int mid, int high) {
    vector temp; // temporary array
    int left = low; // starting index of left half of arr
    int right = mid + 1; // starting index of right half of arr
    int count=0;
    //storing elements in the temporary array in a sorted manner//
    while (left

    • @abhijeettripathi7615
      @abhijeettripathi7615 Год назад

      see do the sorting and counting separately

    • @saillaanil6948
      @saillaanil6948 Год назад +1

      @@abhijeettripathi7615 why can't we do it together

    • @edu_77218
      @edu_77218 Год назад

      ​@@saillaanil6948This is because even if arr[left] > 2*arr[right] is not satisfied, right will be incremented as arr[left] > arr[right]. To calculate cnt, right has to be incremented only when arr[left] > 2*arr[right] is true. So, this requires an extra while loop.

  • @anshbathla3850
    @anshbathla3850 5 месяцев назад +1

    Am I the only one who understood everthing as crystal clear till dry run but during code the mind stopped working

    • @anithusiast.
      @anithusiast. 4 месяца назад

      happened initiallty will take time ..learn basics of coding first

  • @ashnakohli6763
    @ashnakohli6763 7 месяцев назад

    class Solution {
    public int reversePairs(int[] nums) {
    return countInversionsRec(nums);
    }
    int countInversionsRec(int[] arr){
    int l=arr.length;
    if(l

  • @yuvrajanand9342
    @yuvrajanand9342 2 месяца назад

    class Solution {
    public void merge(int [] nums, int low, int mid, int hi){
    ArrayList temp = new ArrayList();
    int left = low;
    int right = mid+1;
    while(left

  • @dewanandkumar8589
    @dewanandkumar8589 Год назад

    Understood

  • @googleit2490
    @googleit2490 Год назад

    Understood :)
    Aug'9, 2023 09:11 pm

  • @mohan-xx8ih
    @mohan-xx8ih Год назад +3

    Leetcode solution
    class Solution {
    void merge(vector &nums, int low, int mid, int high){
    int *temp = new int[high - low + 1];
    int i = low;
    int j = mid + 1;
    int k = 0;
    while((i

  • @sarangkumarsingh7901
    @sarangkumarsingh7901 10 месяцев назад

    Understood.............

  • @pc8803
    @pc8803 Год назад +2

    Hi Striver, I am Btech CSE 4th sem student. I have been following your RUclips channel for a 2-3 weeks now.
    I had a doubt about your SDE Sheet and A-Z DSA sheet .That which one should I complete first
    I already know basics of Cpp, Java and DSA ( I had started doing 375Qs sde sheet of apna college ) I was able to solve questions of problem but my solutions were not optimal approach .
    Please help.

  • @harshitpatil6138
    @harshitpatil6138 11 месяцев назад

    Ubderstood ❤

  • @vikasgupta1828
    @vikasgupta1828 Год назад

    Thanks

  • @aayush5474
    @aayush5474 4 месяца назад

    am i tripping or he keeps saying merge short?

  • @gauravkabdwal309
    @gauravkabdwal309 Год назад

    Understood

  • @sarvansingh6736
    @sarvansingh6736 Год назад

    Got it

  • @luckshaeey
    @luckshaeey Год назад

    understood :)

  • @GeneralistDev
    @GeneralistDev Год назад

    Why below code doesn't work ?
    class Solution
    {
    int cnt = 0;
    void merge(vector &nums, int s, int mid, int e)
    {
    vector temp;
    int i = s, j = mid + 1;
    while (i