Count Inversions | GFG Count Inversions Solution | Seaching and Sorting

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ม.ค. 2025

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

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

    Pepcoding is seriously underrated in DSA game on youtube. Such good explanation on why it works

  • @SohailKhan-dq2qm
    @SohailKhan-dq2qm 10 หลายเดือนก่อน +3

    i wasted my whole day to understand this problem but after that i luckily found this solution and believe me i understood 100%
    what a great explanation by mam
    thankyou so much mam

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

    Manisha ma'am is a legend. She gave such a wonderful explanation!

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

    This is the best ever explaination ever for this

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

    I was frustrating to understand merge sort, then I saw this and every thing is clear. Thank you

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

      Thankyou
      I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
      If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

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

    I literally wasted an hour to understand gfg code but when I watch your solution,
    I just get in one click simplest code &
    explanation is🙌

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

    the way you approach the question is by far the best in internet.

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

    She is a DIVA so beautifully explained. Keep doing the good work and helping students like me

  • @ellis-pr7hh
    @ellis-pr7hh ปีที่แล้ว +2

    literally great explanation ..lot better than anyone..

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

    In love with pepcoding these days.

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

    great ...again i am seeing you as my trainer

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

    Pepcoding never dissapoints!!!Awesome explanation!!

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Glad you liked it
      For better experience and well organised content sign up on nados.io
      Don't forget to follow us on Instagram instagram.com/pepcoding/

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

    Your explanting style is soo sooo soooo good and please put video on recursion and how to do though process on recursion please make video.

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

    had seen many videos but was not able to understand this concept and this video made me understand in a single shot... kudos to the teaching style..... keep growing pepcoding!!!!!

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

    Thanks for very easy explanation of using merge sort to calculate inversion

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

    thank you so much for a soothing explanation. Keep it up Pepcoding.

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

    I guarantee this is the best ever explanation 😃 thanks pepcoding

  • @raviraj-xq4ue
    @raviraj-xq4ue 2 ปีที่แล้ว +1

    kya smjhaya h .....behtareen

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

    Kitna accha padhati ho aap..see, zero dislikes!

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

    Great Great Explanation. Pepcoding is the reason i love doing problem solving.

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

    This channel deserve millions of subs.....awesome ♥

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

    You made it easy. Great Explanation !!!

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

    Great explaination mam i have watched a lot of videos before but couldn't understand the code but finally this video is very helpful for me ....Love the way you explain❤️❤️👍👍

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

    Best explanation of count inversions. Great!

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Glad it was helpful!
      Keep learning.
      And for better experience and well organised content visit nados.pepcoding.com

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

    mindblowing

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

    Excellent Video!

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

    Best ma'am best

  • @RiteshYadav-rc1np
    @RiteshYadav-rc1np 3 ปีที่แล้ว +2

    pepcoding always rocks , thnxx for this .

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      If you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

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

    Your explanation is very clear and outstanding.

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Keep learning.
      And for better experience, visit nados.io, where you will get well curated content and career opportunities.

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

    you are amazing

  • @Ranajit-Surya99
    @Ranajit-Surya99 2 ปีที่แล้ว +1

    plz you make more video. much clear explanation

  • @Aryansingh-fk7hy
    @Aryansingh-fk7hy 3 ปีที่แล้ว +1

    better,better,better than many!.Thanku mam

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

    Best explanation 👍

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

    Excellent explanation manisha ma'am!!

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

      Glad you liked it For better experience and well organised content sign up on nados.io and start learning.

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

    Best Explaination !!

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

    great mem i love it your exprenation of code..

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

    Hats off!! For the level of explanation 🙏🙏

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

    So good... thanks a ton....

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

    Thankyou ma'am!!

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

    Your explanation always outstanding 🙏🔥

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

    really appreciate
    it help a lot .....almost die before came here

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Glad to know that you liked the content and thank you for appreciating.
      The love and respect which I get from you people keep me highly motivated and the same I am able to forward It to you people through my videos.
      So, keep motivating, keep learning and keep loving Pepcoding😊

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

    Best explanation...loved it 💫

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Glad you liked it:) To watch more content like nados.pepcoding.com

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

    Shandarrrr Explanation

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

    Clear and excellent explaination

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Thank you so much and If you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

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

    Thanks. it was the most difficult question

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

    Thanks a lot...really great explanation

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

    Nice..

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

    Thank you for this! really great explanation.

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

    You are a legend.

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Thankyou for your compliment.
      Keep learning.
      And for better experience, visit nados.io, where you will get well curated content and career opportunities.

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

    Awesome !! 🔥

  • @PawanKumar-ot2qs
    @PawanKumar-ot2qs 3 ปีที่แล้ว +1

    Thankyou... Really awesome explanation

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Thank you so much and If you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

    • @yoyocontact5181
      @yoyocontact5181 3 ปีที่แล้ว

      will this videos solution work for 1,9,6,4,5 ? i tried but it doesnt show correct ans it says 3 but answer is 5

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

      @@yoyocontact5181
      class Solution
      {
      // arr[]: Input Array
      // N : Size of the Array arr[]
      //Function to count inversions in the array.
      private static long count=0;
      static long inversionCount(long arr[], long N)
      {
      // Your Code Here
      long arr1[]=mergeSort(arr,0,arr.length-1);
      //System.out.println(Arrays.toString(arr1));
      return count;
      }
      private static long[] mergeSort(long arr[],long left,long right){
      if(left==right){
      long[] a=new long[1];
      a[0]=arr[(int)left];
      return a;
      }
      long mid=left+(right-left)/2;
      long leftArr[]=mergeSort(arr,left,mid);
      long rightArr[]=mergeSort(arr,mid+1,right);
      long mergedArr[]=merge(leftArr,rightArr);
      return mergedArr;
      }
      private static long[] merge(long leftA[],long rightA[]){
      long[] mArr=new long[leftA.length+rightA.length];
      int i=0,j=0,k=0;
      while(i

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

    Hatts off 🙏

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Keep learning.
      And for better experience, visit nados.io, where you will get well curated content and career opportunities.

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

    👍👍👍👍

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

    Great video! Plz also upload the video for count of smaller nodes after self. That is also done by mergesort

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      As soon as possible

    • @yoyocontact5181
      @yoyocontact5181 3 ปีที่แล้ว

      will this videos solution work for 1,9,6,4,5 ? i tried but it doesnt show correct ans it says 3 but answer is 5

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

      @@yoyocontact5181 yes

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

    This code failed to pass tetscases on gfg

  • @letsdoeverythinginoneweek9398
    @letsdoeverythinginoneweek9398 3 ปีที่แล้ว

    nice and easy
    very good explanationn

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem.
      If you like our efforts, we request a review
      g.page/Pepcoding/review?rc
      You can subscribe to our channel here
      th-cam.com/users/Pepcodingabout?view_as=subscriber

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

    thankyou

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

    🙌👌⭐

  • @apurvgarg4368
    @apurvgarg4368 3 ปีที่แล้ว

    simple code in 10 lines
    def count_inversions(a):
    res = 0
    counts = [0]*(len(a)+1)
    rank = { v : i+1 for i, v in enumerate(sorted(a)) }
    for x in reversed(a):
    i = rank[x] - 1
    while i:
    res += counts[i]
    i -= i & -i
    i = rank[x]
    while i

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

    Thanks Mam :-)

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

      Hope you like the video, for better experience and well organised content visit - nados.io

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

    very good explanation
    thank you @pepcoding team for such a amazing video

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Glad you liked it!
      For better experience, visit nados.io, where you will get well curated content and career opportunities.

  • @nikhilvashisht2810222
    @nikhilvashisht2810222 3 ปีที่แล้ว

    Thankyou for this! really helped.

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

      Glad it helped and If you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

    • @nikhilvashisht2810222
      @nikhilvashisht2810222 3 ปีที่แล้ว

      @@Pepcoding sure 👍

    • @yoyocontact5181
      @yoyocontact5181 3 ปีที่แล้ว

      will this videos solution work for 1,9,6,4,5 ? i tried but it doesnt show correct ans it says 3 but answer is 5

  • @SURAJKUMAR-nl3ly
    @SURAJKUMAR-nl3ly 2 ปีที่แล้ว +1

    Such a wonderful explanation... thank you mam.. _/\_

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

    sir ye recursive algo hai aur humne global variable ka use kiya hai interview mei problem to nhi hogi na iss method se

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

    thik h jiii

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

    At geeksForGeeks portal at different test cases this solution is not giving the desired result.

  • @adnaan8485
    @adnaan8485 3 ปีที่แล้ว

    it took me 1 hr to understand why this video has got zero dislikes

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Glad to know that you liked the content and thank you for appreciating.
      The love and respect which I get from you people keep me highly motivated and the same I am able to forward It to you people through my videos.
      So, keep motivating, keep learning and keep loving Pepcoding😊

    • @adnaan8485
      @adnaan8485 3 ปีที่แล้ว

      @@Pepcoding and onemore thing i wanted to ask im currently in begin of 3rd year(B.tech) will i be able to learn every thing in 1 year and get product based companies

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

    Can you please explain me how to write 28 and 29 line of code in c++...plz help me

    • @manishapawar3471
      @manishapawar3471 3 ปีที่แล้ว

      Use vector instead of array in cpp, vector has a size function and it is easy to use.

  • @sujitkumar-xs2wy
    @sujitkumar-xs2wy 3 ปีที่แล้ว

    Thanks🙏✨💯

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      You’re welcome 😊

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

    can we write code in c++ by returning array ?

    • @manishapawar3471
      @manishapawar3471 3 ปีที่แล้ว

      Yes you can
      int* fun() {} , you have to receive this like int*arr = fun();

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      visit nados.pepcoding.com; post your query, there our community will help you out.

  • @atharvakulkarni2024
    @atharvakulkarni2024 3 ปีที่แล้ว

    If this que comes up in the interview and if he asks have u done this question first when i try to explain him this method after explaining the brute force method then what i should say?Bec merge sort method is not intuitive..concept used is intuitive but method is not?How should one proceed in such scenerio?

    • @freshcontent3729
      @freshcontent3729 3 ปีที่แล้ว

      will this videos solution work for 1,9,6,4,5 ? i tried but it doesnt show correct ans it says 3 but answer is 5 , bro can you please try

    • @satyammishra5869
      @satyammishra5869 3 ปีที่แล้ว

      @@freshcontent3729 yes it is working

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

    aapke white board ka ky name h
    plzz reply

  • @NeerajSharma-mz4es
    @NeerajSharma-mz4es 3 ปีที่แล้ว

    Will this work for array having duplicates values

    • @mickyman753
      @mickyman753 3 ปีที่แล้ว

      yup ,inversion just means a ele on index i>index j ele on right ,duplicates won't matter here , 4 5 4 4,here 5-4 and 5-4 are making two inversion

  • @indranilchakraborty5949
    @indranilchakraborty5949 3 ปีที่แล้ว

    we can also solve it using fenwick tree....

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

    why always pepcoding...

  • @yoyocontact5181
    @yoyocontact5181 3 ปีที่แล้ว

    will this videos solution work for 1,9,6,4,5 ? i tried but it doesnt show correct ans it says 3 but answer is 5

  • @dietpepsi7338
    @dietpepsi7338 3 ปีที่แล้ว

    493. Reverse Pairs
    isi way se leetcode 493 kia pr tle aa rha hai

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

    22:48

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

    Your explanation is good. However, returning the array from merge sort functions is not good.
    Also taking global static variables is also not good. Ideally, a function should return the answer.
    A good company's interviewer won't accept this.
    So this could be the code without any global static variable:
    class Solution {
    int getInversionCount(int[] array) {
    return mergeSort(array, 0, array.length - 1);
    }
    private int mergeSort(int[] array, int low, int high){
    int count = 0;
    if(low < high){
    int mid = low + (high - low) / 2;
    count += mergeSort(array, low, mid);
    count += mergeSort(array, mid + 1, high);
    count += merge(array, low, mid, high);
    }
    return count;
    }
    private int merge(int array[], int low, int mid, int high){
    int inversion = 0;
    int tempArray[] = new int[high - low + 1];
    int index1 = low;
    int index2 = mid + 1;
    int arr1Size = mid + 1;
    int arr2Size = high + 1;
    int mergedArrIndex = 0;
    while(index1 < arr1Size && index2 < arr2Size){
    if(array[index1]

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

    Amazing explanation !! thank you so much!!!

  • @nikhilaggarwal9325
    @nikhilaggarwal9325 3 ปีที่แล้ว

    sir ye recursive algo hai aur humne global variable ka use kiya hai interview mei problem to nhi hogi na iss method se