Count Inversions in an Array | Brute and Optimal

Поділитися
Вставка
  • Опубліковано 16 лип 2024
  • Problem Link: bit.ly/3GJcuYj
    Notes/C++/Java/Python codes: takeuforward.org/data-structu...
    We have solved the problem, and we have gone from brute force and ended with the most optimal solution. Every approach's code has been written in the video itself. Also, we have covered the algorithm with intuition.
    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
    00:40 Problem Statement
    02:11 Brute force approach
    02:52 Pseudocode
    03:35 Complexity
    04:05 Optimmal solution
    04:22 Intuition
    10:33 Approach + Dry-run
    18:02 Code
    22:37 Complexity

КОМЕНТАРІ • 192

  • @takeUforward
    @takeUforward  10 місяців тому +12

    Please watch our new video on the same topic: ua-cam.com/video/AseUmwVNaoY/v-deo.html

    • @namannema3349
      @namannema3349 8 місяців тому +4

      this link take u to the same video we are watching

    • @yogeshkaushik8316
      @yogeshkaushik8316 3 місяці тому +10

      @@namannema3349 thats what recursion means

  • @satvrii
    @satvrii Рік тому +81

    Nowadaya strivers voice has become so calm and soft 😅❤

  • @anuplohar23
    @anuplohar23 6 місяців тому +16

    Best count inversion video on UA-cam, your method of teaching is very best that it gets me understand very easily 🌟🌟🌟

  • @_AASHISHSHAH
    @_AASHISHSHAH Рік тому +8

    this is the best playlist in world. thank you stiver for your effort.

  • @SuvradipDasPhotographyOfficial
    @SuvradipDasPhotographyOfficial Рік тому +10

    The best count inversion video on UA-cam.. Thanks a lot Raj.. stay blessed❤

  • @Manishgupta200
    @Manishgupta200 Рік тому +17

    I'm trying this problem and solved it by myself by taking count as global variable.. But you taught us in a vary optimal way without taking count as a global variable. Really best optimal approach. Thankyou ❤

    • @bishakhdutta8427
      @bishakhdutta8427 Рік тому +1

      whats the complexity of your solution?
      can you share it?

    • @Manishgupta200
      @Manishgupta200 Рік тому +1

      @@bishakhdutta8427 same as merger sort merge algorithm

  • @cinime
    @cinime Рік тому +13

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

  • @gajendrakumar8271
    @gajendrakumar8271 2 місяці тому +1

    Finally completed this recursion playlist and Thanks a lot striver for great explanation throughout and patiently drawing recursion tree. patience is the key to solve and teach anything . And you have it man and you are teaching that too. Thanks a lot again

  • @bmishra98
    @bmishra98 5 днів тому

    Completed the playlist. This was the best recursion playlist I ever went through. Thanks a lot Striver.

  • @senseiAree
    @senseiAree 9 місяців тому +4

    Striver your voice is very soothing and calm bro ❤.... I use it to sleep at night AND study... and I don't feel sleepy

  • @vikasbagri1225
    @vikasbagri1225 Рік тому +3

    Understood it very well
    Thanks for this amazing series

  • @akritisneh2849
    @akritisneh2849 Рік тому +4

    So much crystal clear!!!!Thank youu❤

  • @prateekgoyal7009
    @prateekgoyal7009 Рік тому +1

    This is the best explanation I've ever got.

  • @user-jm6bc3rt5e
    @user-jm6bc3rt5e Місяць тому +1

    Understood
    THE BEST EXPLANATION
    Excellent playlist 👌 👏 ❤

  • @pallavi22222
    @pallavi22222 Рік тому +1

    your problem solving approach explanation is superb

  • @selvaarumugam370
    @selvaarumugam370 Рік тому +2

    As usual your teaching jus made coding much easier than it is bruh!! Waiting for Binary Search series bruh!!!!

  • @chiragbirla5606
    @chiragbirla5606 Рік тому +1

    Best explanation ever for this problem

  • @8bit_hero850
    @8bit_hero850 3 місяці тому +6

    Can we realistically solve this if it comes in an interview given we haven't solved it before? I mean how do can you get the intuition of merge sort from this problem? I really don't get it.

  • @mehulthuletiya497
    @mehulthuletiya497 Рік тому +20

    Timestamps:
    ---------------------
    00:40 Problem Statement
    02:11 Brute force approach
    02:52 Pseudocode
    03:35 Complexity
    04:05 Optimmal solution
    04:22 Intuition
    10:33 Approach + Dry-run
    18:02 Code
    22:37 Complexity

  • @lakshaysawhney9988
    @lakshaysawhney9988 7 днів тому

    Thoroughly enjoyed the problem!!

  • @aditijagtap7853
    @aditijagtap7853 5 годин тому

    Best teaching approach so far!!!!

  • @cartidise
    @cartidise Рік тому +11

    I usually don't comment but wanted to say that just subbed your channel. This is the best explanation I've ever got. THANKS A LOT:>)

  • @mohd786ishaan
    @mohd786ishaan 10 місяців тому +1

    UNDERSTOOD SIR ! GREAT EXPLAINATION

  • @unnatishukla8513
    @unnatishukla8513 10 місяців тому +1

    awesome as always!!!!🤩

  • @shiveshgupta1705
    @shiveshgupta1705 Рік тому +1

    i just imagine if all the problems would be available on this channel in future

  • @SaumyaSharma007
    @SaumyaSharma007 11 місяців тому +1

    OMG Bawal explanation Striver Bhaiya.😃

  • @pavanjegurupati
    @pavanjegurupati 4 місяці тому

    Great explanation!!

  • @gauristar4094
    @gauristar4094 11 днів тому

    Superb logic, Understood!!!

  • @Sumeet_100
    @Sumeet_100 6 місяців тому

    Thank you for this video !!

  • @sukhpreetsingh5200
    @sukhpreetsingh5200 Рік тому +1

    Understood amazing explanation

  • @theresilientpianist7114
    @theresilientpianist7114 6 місяців тому

    Really it was a great series Striver.🔥🔥

  • @GuruPrasadShukla
    @GuruPrasadShukla Рік тому +1

    understood the approach sir
    thanks alot

  • @ishangujarathi10
    @ishangujarathi10 9 місяців тому

    loved the optimal solution, intuition op!

  • @the_haryannvi_coder
    @the_haryannvi_coder Місяць тому

    If u don't wanna use cnt in mergeSort function, you can do this:-
    int mergeSort(vector &arr, int low, int high) {
    if (low >= high) return 0;

    int mid = (low + high) / 2 ;
    int left = mergeSort(arr, low, mid); // left half
    int right = mergeSort(arr, mid + 1, high); // right half
    int m = merge(arr, low, mid, high); // merging sorted halves
    return left + right + m;
    }

  • @abhaypatel379
    @abhaypatel379 Місяць тому

    thanks striver for making a complex question into very easy question
    🤗

  • @saitehith6647
    @saitehith6647 Рік тому

    Superb Explanation

  • @NazeerBashaShaik
    @NazeerBashaShaik 3 місяці тому

    Understood, thank you.

  • @ishasinghal3457
    @ishasinghal3457 7 місяців тому

    Best explanation ever

  • @abhishekverma4693
    @abhishekverma4693 4 місяці тому

    thank you so much for watching

  • @yashisrivastava6196
    @yashisrivastava6196 10 місяців тому +1

    just wow explanation

  • @sivasaimanchem4399
    @sivasaimanchem4399 Рік тому

    All i can say is Thankyou so much ❤🙌

  • @vaibhav56
    @vaibhav56 6 днів тому

    I was struggling with the solution but as soon as you mentioned merge sort it clicked in my mind

  • @steverogers7050
    @steverogers7050 3 місяці тому

    very nice explanation bhaiya

  • @xtzyrox2764
    @xtzyrox2764 Рік тому +12

    I am happy with the brute force now I will see optimal 1 week before interview bcz University exams are in this month

  • @HR-pz7ts
    @HR-pz7ts 2 місяці тому

    Amazing I solved two questions using the same logic.

  • @hashcodez757
    @hashcodez757 4 місяці тому

    understood Bhaiya!!

  • @navdeepkumar9160
    @navdeepkumar9160 11 місяців тому +1

    Great video

  • @AbjSir
    @AbjSir 9 місяців тому

    // Everytime while sorting you move an element to the left (assume nobody moves to right agar chote walo ko aana hoga to left me aa jayenge)
    // if an element crosses another element while moving to the left for the purpose of sorting then it should increase the count of inversion

  • @grm642
    @grm642 5 місяців тому

    Thank you😊

  • @sarangkumarsingh7901
    @sarangkumarsingh7901 3 місяці тому

    Nice lecture................

  • @rohitkumarpilania94
    @rohitkumarpilania94 Рік тому

    Badhiya kaam kar rahe ho, see you soon

  • @user-ck6kn1ty8x
    @user-ck6kn1ty8x 5 місяців тому +1

    Thank You Bhaiya

  • @anshasati1920
    @anshasati1920 22 дні тому

    Understood Sir🥳

  • @pushankarmakar1783
    @pushankarmakar1783 5 місяців тому +1

    understood!
    def merge(arr,l,mid,h):
    temp=[]
    i=l
    j=mid+1
    cnt=0
    while i

  • @nishant4595
    @nishant4595 Місяць тому +1

    understood!!!

  • @ShubhamKumar-uf3gc
    @ShubhamKumar-uf3gc Місяць тому

    loved that bhaiya

  • @venup2813
    @venup2813 Рік тому

    Understood brother❤️

  • @YourCodeVerse
    @YourCodeVerse 8 місяців тому

    Understood✅🔥🔥

  • @ravalikatalks5285
    @ravalikatalks5285 5 місяців тому

    thanks alot bhaiya

  • @satyamgupta4808
    @satyamgupta4808 10 місяців тому +1

    very nice video

  • @nikhilprakashahir5730
    @nikhilprakashahir5730 5 місяців тому

    so aweesome

  • @divyaanandhan6021
    @divyaanandhan6021 Рік тому

    Thanks 😊👍

  • @HarshChoudhary-vm6eh
    @HarshChoudhary-vm6eh Рік тому

    Understood thats great...

  • @NoniSabharwal
    @NoniSabharwal 2 місяці тому

    The way he said wow! Uff in love with the voice

  • @abhishekahirvar7783
    @abhishekahirvar7783 Місяць тому

    thanks mate

  • @her_soulmate
    @her_soulmate 7 місяців тому

    Understood 🎉

  • @vikasgupta1828
    @vikasgupta1828 Рік тому

    Thanks

  • @GhostVaibhav
    @GhostVaibhav 4 місяці тому

    Understood🔥

  • @muqeemuddin8057
    @muqeemuddin8057 4 місяці тому +1

    Hey, can you make a video on binary insertion sort and compare it's time complexities with insertion sort. Thanks for your videos on DSA.

  • @varunpalsingh3822
    @varunpalsingh3822 Рік тому

    understood 👍👍

  • @user-nk1mb5fy7j
    @user-nk1mb5fy7j Рік тому

    UNDERSTOOD

  • @RituSingh-ne1mk
    @RituSingh-ne1mk 7 місяців тому

    Understood!

  • @vivekbhore5722
    @vivekbhore5722 3 місяці тому

    thank u striver

  • @atharva3571
    @atharva3571 6 місяців тому

    I understood the problem

  • @mount2020
    @mount2020 Рік тому

    Thank u bhai

  • @user-lw9dj8we7k
    @user-lw9dj8we7k 6 місяців тому

    Understood sir

  • @culeforever5408
    @culeforever5408 8 місяців тому +1

    understood :)

  • @infomania_by_ayush7901
    @infomania_by_ayush7901 28 днів тому +1

    Understood, but I am gonna need some time to implement this.

  • @nayankhuman1043
    @nayankhuman1043 7 днів тому

    Understood :)

  • @hemantpatel1413
    @hemantpatel1413 24 дні тому

    understood.

  • @pritipatil4021
    @pritipatil4021 11 місяців тому

    Understood...!!!!

  • @AnjuGupta-sz1uk
    @AnjuGupta-sz1uk 10 місяців тому +1

    understood

  • @vk-mc5tq
    @vk-mc5tq 3 місяці тому

    Global vs Local
    In Global variables values updated dynamically but in local variables we need to pass updated values (manually) to subsequent functions

  • @hitheshpk6030
    @hitheshpk6030 Рік тому

    Understood

  • @user-je7tz6le4k
    @user-je7tz6le4k 11 місяців тому +3

    These types of questions always demotivate me... like how you can think of such kind of solution in an interview

  • @soumiyamuthuraj3516
    @soumiyamuthuraj3516 25 днів тому

    awesome

  • @ajaykr2811
    @ajaykr2811 9 місяців тому

    13:05 the kind of excitement I want while learning DSA.

  • @MJBZG
    @MJBZG 22 дні тому

    didn't understand much but will try again

  • @TheNullDeveloper
    @TheNullDeveloper 15 днів тому

    understood the solution . But how do i get the intution that it will solve in this way i.e using this approach 😕 in most of the cases i don't have idea about the optimal one how would I approach it

  • @VaibhavSethF
    @VaibhavSethF Місяць тому

    Hi Striver , is creating static variables in interview is a bad practice?

  • @hetchaudhari
    @hetchaudhari Місяць тому

    Is it fine to pass variables by reference?Or should we avoid that too in the interviews?

  • @ChhaviAayushi-qh4zx
    @ChhaviAayushi-qh4zx Рік тому +1

    Good Afternoon sir
    sir in my college it's hard to get on campus INTERNSHIP can you please advice so that I can get an internship in my third year .
    Thanks

  • @addy1268
    @addy1268 5 місяців тому

    can anybody pls explain why we cant/ should'nt declare the 'cnt' variable globally ?

  • @subodhkasaudhaniitk796
    @subodhkasaudhaniitk796 Рік тому

    Gold

  • @ANURAGSINGH-nl2ll
    @ANURAGSINGH-nl2ll 10 місяців тому

    cleared

  • @anirudhrana5578
    @anirudhrana5578 5 днів тому

    🔥🔥🔥🔥🔥

  • @notcountdankula
    @notcountdankula 11 місяців тому

    I used an array of 1 size and passed it by reference to count the pairs.

  • @johndurai2226
    @johndurai2226 8 місяців тому

    00:00

  • @Am-ss3gy
    @Am-ss3gy 11 місяців тому

    ❤❤

  • @hardikg6858
    @hardikg6858 4 місяці тому

    can i solve this question using pbds