Count Inversions in an Array | Brute and Optimal

Поделиться
HTML-код
  • Опубликовано: 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

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

  • @takeUforward
    @takeUforward  10 месяцев назад +12

    Please watch our new video on the same topic: ruclips.net/video/AseUmwVNaoY/видео.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 RUclips, 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 RUclips.. 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!!

  • @bmishra98
    @bmishra98 5 дней назад

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

  • @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

  • @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

  • @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!!

  • @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

  • @8bit_hero850
    @8bit_hero850 3 месяца назад +5

    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.

  • @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 10 дней назад

    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

  • @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;
    }

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

    loved the optimal solution, intuition op!

  • @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 5 дней назад

    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 27 дней назад +1

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

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

    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

  • @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

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

    Understood

  • @soumiyamuthuraj3516
    @soumiyamuthuraj3516 24 дня назад

    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 14 дней назад

    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

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

    Time Stamps:
    --------------------------------------------------
    00:40 Problem Statement