Count Inversions in Array

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

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

  • @venkatasriharsha4227
    @venkatasriharsha4227 3 года назад +9

    OMG 😱 never thought this would be that easy. Can't stop u appreciating for solving Gfg questions 👏. Keep posting, Thanks dude

  • @hariharibolll3459
    @hariharibolll3459 Год назад +5

    Dhanyawad MataJi. 🌸🙌🙏

  • @ashfaqmurshed503
    @ashfaqmurshed503 2 года назад +8

    class Solution{
    public:
    long long int count=0;
    long long int inversionCount(long long arr[], long long N)
    {
    mergesort(arr,0,N-1);
    return count;
    }
    long long int* mergesort(long long arr[],long long low, long long high)
    {
    if(low==high)
    {
    long long int* ans=new long long int[1];
    ans[0]=arr[low];
    return ans;
    }
    long long mid=(low+high)/2;
    long long int* left=mergesort(arr,low,mid);
    long long int* right=mergesort(arr,mid+1,high);
    return merge(left,right,mid-low+1,high-mid);
    }
    long long int* merge(long long int* left,long long int* right,int n, int m)
    {
    int i=0;
    int j=0;
    long long int* ans=new long long int[n+m+1];
    int k=0;
    while(i

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

    your explanation is so easy, carry on

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

    Superb explination ! I always understand your explination in one go ,, thankyou

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

    Thanku you so much Alisha ...Amazing explanation!!!😎

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

    Thank you for the great explanation, you gain a new subscriber.

  • @darshankalathiya8667
    @darshankalathiya8667 2 года назад

    kitne dino se pata nai chal raha tha aaj cancept clear huaa thank you so much mem.

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

    how count+=n-i;,how did u come up with this ??

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

    Best Explanation.

  • @ghanshyampatil5850
    @ghanshyampatil5850 2 года назад

    Great Explaination!!!

  • @harshkumaryadav3676
    @harshkumaryadav3676 2 года назад

    😍🥰

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

    In python .....it is giving correct answer when count+=n-i+1.....in 52th line.........can you please tell me why

  • @rasputin3571
    @rasputin3571 2 года назад

    Great Explaination

  • @nitinrai5053
    @nitinrai5053 2 года назад

    Such a nice explanation 🔥

  • @yatri6329
    @yatri6329 3 года назад +2

    Is this Q over Leetcode??

  • @basavarajhadimani4493
    @basavarajhadimani4493 2 года назад +1

    While passing mid to mergearrays function why did you pass it as (mid-low+1) why not simply (mid+1) and also for the high too... Could you please explain that part?

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

      return merge(left,right,mid-low+1,high-mid);
      long long int* merge(long long int* left,long long int* right,int n, int m),lets see, actually n and m size of left and right array

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

      because its a length of a array

  • @GhostRider....
    @GhostRider.... 2 года назад

    Thank you Mam ,nicely explained

  • @bluegreen-
    @bluegreen- Год назад +1

    Hi Alisha, such an amazing explanation!!
    Btw there is another similar problem in leetcode called the reverse Pairs,
    I applied the same logic but i'm not able to get the output!
    class Solution {
    int count=0;
    public int reversePairs(int[] nums) {

    int N=nums.length;
    int a[]=mergesort(nums,0,N-1);
    return count;
    }
    public int[] mergesort(int arr[],int low,int high)
    {
    if(low==high)
    {
    int[] ans=new int[1];
    ans[0]=arr[low];
    return ans;
    }
    int mid=(low+high)/2;
    int[] left=mergesort(arr,low,mid);
    int[] right=mergesort(arr,mid+1,high);
    return merge(left,right,mid-low+1,high-mid);
    }
    public int[] merge(int[] left,int[] right,int n, int m)
    {

    int i=0;
    int j=0;
    int[] ans=new int[n+m+1];
    int k=0;
    while(i

  • @SajanKumar-ec2us
    @SajanKumar-ec2us Год назад

    Explain why count + =n-i is ans

  • @anshvashisht8519
    @anshvashisht8519 2 года назад

    the thing you and i have same is number of tabs in chrome😂

  • @amarshinde5863
    @amarshinde5863 3 года назад

    nice

  • @AmanYadav-oe6wt
    @AmanYadav-oe6wt Год назад

    Its not working buddy.