Count Inversions in an Array | Brute and Optimal

  Рет қаралды 258,576

take U forward

take U forward

Күн бұрын

Пікірлер: 256
@takeUforward
@takeUforward Жыл бұрын
Please watch our new video on the same topic: kzbin.info/www/bejne/d6TIhqCti7OUpbs
@namannema3349
@namannema3349 Жыл бұрын
this link take u to the same video we are watching
@yogeshkaushik8316
@yogeshkaushik8316 9 ай бұрын
@@namannema3349 thats what recursion means
@user-ic7xs9vh7i
@user-ic7xs9vh7i 4 ай бұрын
@@yogeshkaushik8316 😆
@anuplohar23
@anuplohar23 Жыл бұрын
Best count inversion video on KZbin, your method of teaching is very best that it gets me understand very easily 🌟🌟🌟
@satvrii
@satvrii Жыл бұрын
Nowadaya strivers voice has become so calm and soft 😅❤
@anuradha3868
@anuradha3868 Жыл бұрын
True...as compared to his previous vdos 😂
@newsbuster2194
@newsbuster2194 Жыл бұрын
😂
@shubhamkumar-hx1fb
@shubhamkumar-hx1fb Жыл бұрын
​@@anuradha3868 same thought 😂
@saswatrath4646
@saswatrath4646 8 ай бұрын
abe mic kharap tha pehle😂
@THEReFleX
@THEReFleX Ай бұрын
ladki ka chakar
@attackgaming9940
@attackgaming9940 4 ай бұрын
Making the complex problem looks simpler is a kind of skill that striver only has🛐
@Manishgupta200
@Manishgupta200 Жыл бұрын
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 Жыл бұрын
whats the complexity of your solution? can you share it?
@Manishgupta200
@Manishgupta200 Жыл бұрын
@@bishakhdutta8427 same as merger sort merge algorithm
@bmishra98
@bmishra98 5 ай бұрын
Completed the playlist. This was the best recursion playlist I ever went through. Thanks a lot Striver.
@_AASHISHSHAH
@_AASHISHSHAH Жыл бұрын
this is the best playlist in world. thank you stiver for your effort.
@SuvradipDasPhotographyOfficial
@SuvradipDasPhotographyOfficial Жыл бұрын
The best count inversion video on KZbin.. Thanks a lot Raj.. stay blessed❤
@gajendrakumar8271
@gajendrakumar8271 8 ай бұрын
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
@mehulthuletiya497
@mehulthuletiya497 Жыл бұрын
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
@senseiAree
@senseiAree Жыл бұрын
Striver your voice is very soothing and calm bro ❤.... I use it to sleep at night AND study... and I don't feel sleepy
@mranonymous1982
@mranonymous1982 Ай бұрын
Bro what
@MehtabReviews
@MehtabReviews Жыл бұрын
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:>)
@vaibhav56
@vaibhav56 5 ай бұрын
I was struggling with the solution but as soon as you mentioned merge sort it clicked in my mind
@cinime
@cinime Жыл бұрын
Understood! Super amazing explanation as always, thank you very very very much for your effort!!
@shiveshgupta1705
@shiveshgupta1705 Жыл бұрын
i just imagine if all the problems would be available on this channel in future
@PriyaGanti-m7c
@PriyaGanti-m7c 3 ай бұрын
I understood the solution clearly... Thank you very much, sir.
@selvaarumugam370
@selvaarumugam370 Жыл бұрын
As usual your teaching jus made coding much easier than it is bruh!! Waiting for Binary Search series bruh!!!!
@aradhyaagrawal4766
@aradhyaagrawal4766 3 ай бұрын
00:06 Count the number of pairs in an array where the left element is greater than the right element. 02:12 Brute Force solution 04:10 Counting the number of pairs in two sorted arrays where the left element is from the left array and the right element is from the right array, and the right element is smaller than the left element. 06:11 Inversion count can be found by counting the number of elements greater than the element on its right in a sorted array 08:28 The number of pairs formed in an array can be determined using the merge sort algorithm. 10:41 Counting inversions in an array by merging sorted subarrays. 13:03 Count the inversions in an array using a merge sort algorithm 15:17 Merge sort algorithm helps in counting inversions in an array 17:25 Count the number of inversions in an array 19:15 Count the number of inversions in an array 21:08 The solution uses a recursive function to merge and count inversions in an array. 22:51 The time complexity of counting inversions is O(n log n) and it requires extra space to merge arrays.
@InduAnuga
@InduAnuga 7 ай бұрын
Understood THE BEST EXPLANATION Excellent playlist 👌 👏 ❤
@prateek5208
@prateek5208 5 ай бұрын
such an awesome expalination bhaiya just approach dekhkr hi dimag ma intution agya ki merge ma kase implement krenge , you are best
@aditijagtap7853
@aditijagtap7853 5 ай бұрын
Best teaching approach so far!!!!
@bgmihighlights6378
@bgmihighlights6378 Ай бұрын
Omg Striver you are great , someday will love to reach at your level!
@prateekgoyal7009
@prateekgoyal7009 Жыл бұрын
This is the best explanation I've ever got.
@xtzyrox2764
@xtzyrox2764 Жыл бұрын
I am happy with the brute force now I will see optimal 1 week before interview bcz University exams are in this month
@b39_navkaransingh73
@b39_navkaransingh73 Жыл бұрын
Did anyone ask you?
@SaumyaSharma007
@SaumyaSharma007 Жыл бұрын
OMG Bawal explanation Striver Bhaiya.😃
@sourabhsoni5065
@sourabhsoni5065 14 күн бұрын
Just cleared the intution so well.
@pallavi22222
@pallavi22222 Жыл бұрын
your problem solving approach explanation is superb
@pranavdharkar
@pranavdharkar 2 сағат бұрын
I feel so happy when i saw that the merge function returns the cnt and then add it to the ans i had exactly done the same
@the_haryannvi_coder
@the_haryannvi_coder 7 ай бұрын
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; }
@lakshaysawhney9988
@lakshaysawhney9988 5 ай бұрын
Thoroughly enjoyed the problem!!
@chiragbirla5606
@chiragbirla5606 Жыл бұрын
Best explanation ever for this problem
@shashwatpandey3285
@shashwatpandey3285 2 ай бұрын
took me 1 day to solve this problem on my own , no outside help or anything , when i first saw the problem it was like hmm , we want total number of elements less than arr[i] on its right side , so it was basically like the array was being spilt, at first i coded the bruteforce which was very easy ofcoursse , and then i had to brainstorm for hours , in the question it was said the inversion count tells us how far or close the array is from being sorted , thats when merge sort came into my mind , because as i said earlier we want number of elements less than arr[i] on the right side of i , merge sort was the only soritng algo i studied in which arrays were being split and i thought while merging 2 sorted arrays we can count the number of elements smaller than arr[i[, from the right side of the splitted array
@vikasbagri1225
@vikasbagri1225 Жыл бұрын
Understood it very well Thanks for this amazing series
@akritisneh2849
@akritisneh2849 Жыл бұрын
So much crystal clear!!!!Thank youu❤
@8bit_hero850
@8bit_hero850 9 ай бұрын
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.
@unknown47896
@unknown47896 5 ай бұрын
no way bro
@flakky626
@flakky626 4 ай бұрын
Exactly my thought, No way you gonnna come up with something like that on your own
@NoniSabharwal
@NoniSabharwal 8 ай бұрын
The way he said wow! Uff in love with the voice
@iamnoob7593
@iamnoob7593 24 күн бұрын
Brilliant video. Thank you striver
@abhishekverma4693
@abhishekverma4693 10 ай бұрын
thank you so much for watching
@the_avii_7
@the_avii_7 23 күн бұрын
Please take care, in this problem inside 1st while loop if-condition should be { lesser than equal to ---> if ( arr[left]
@vishakhakhanna8115
@vishakhakhanna8115 2 ай бұрын
Understood! Great explaination.
@abhaypatel379
@abhaypatel379 6 ай бұрын
thanks striver for making a complex question into very easy question 🤗
@GnaniDarshan
@GnaniDarshan 12 күн бұрын
Nice intution! Thanks
@elamaran350
@elamaran350 3 ай бұрын
Understood ❤ At last
@AbjSir
@AbjSir Жыл бұрын
// 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
@creepitup
@creepitup 6 күн бұрын
@mohd786ishaan
@mohd786ishaan Жыл бұрын
UNDERSTOOD SIR ! GREAT EXPLAINATION
@HR-pz7ts
@HR-pz7ts 8 ай бұрын
Amazing I solved two questions using the same logic.
@theresilientpianist7114
@theresilientpianist7114 11 ай бұрын
Really it was a great series Striver.🔥🔥
@rushidesai2836
@rushidesai2836 24 күн бұрын
Crazy good solution.
@harigs72
@harigs72 3 ай бұрын
Happy teacher day 🎉❤
@kaichang8186
@kaichang8186 3 ай бұрын
Thanks for the great video, well understood
@shaikhanuman8012
@shaikhanuman8012 4 ай бұрын
good explanation on count inversion
@ishangujarathi10
@ishangujarathi10 Жыл бұрын
loved the optimal solution, intuition op!
@pushankarmakar1783
@pushankarmakar1783 11 ай бұрын
understood! def merge(arr,l,mid,h): temp=[] i=l j=mid+1 cnt=0 while i
@gauristar4094
@gauristar4094 5 ай бұрын
Superb logic, Understood!!!
@muqeemuddin8057
@muqeemuddin8057 10 ай бұрын
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.
@KapilMaan-vw9sd
@KapilMaan-vw9sd 3 ай бұрын
thanks sir for making this wonderful video sir !!!
@shivanshagrawal4179
@shivanshagrawal4179 Ай бұрын
understood the solution striver thankyou
@harim7945
@harim7945 8 күн бұрын
Striver is my man crush now lol after Tom cruise....jk You are great man....your videos help me a lot!
@JatinKumar-pl4sq
@JatinKumar-pl4sq 3 ай бұрын
Bro u have destroyed all so called tech schools
@ishasinghal3457
@ishasinghal3457 Жыл бұрын
Best explanation ever
@pavanjegurupati
@pavanjegurupati 9 ай бұрын
Great explanation!!
@ganeshjaggineni4097
@ganeshjaggineni4097 Ай бұрын
NICE SUPER EXCELLENT MOTIVATED
@prabhakaran5542
@prabhakaran5542 3 ай бұрын
Understood ❤
@ajaykr2811
@ajaykr2811 Жыл бұрын
13:05 the kind of excitement I want while learning DSA.
@unnatishukla8513
@unnatishukla8513 Жыл бұрын
awesome as always!!!!🤩
@MJBZG
@MJBZG 6 ай бұрын
didn't understand much but will try again
@yashisrivastava6196
@yashisrivastava6196 Жыл бұрын
just wow explanation
@sivasaimanchem4399
@sivasaimanchem4399 Жыл бұрын
All i can say is Thankyou so much ❤🙌
@sukhpreetsingh5200
@sukhpreetsingh5200 Жыл бұрын
Understood amazing explanation
@309_dussasainath8
@309_dussasainath8 3 ай бұрын
arr=[2,4,1,3,5] count=0 res=[] for i in range(len(arr)-1,-1,-1): res.append(arr[i]) res.sort() j=0 while jres[j]: count+=1 j+=1 print(count) try this
@vk-mc5tq
@vk-mc5tq 9 ай бұрын
Global vs Local In Global variables values updated dynamically but in local variables we need to pass updated values (manually) to subsequent functions
@steverogers7050
@steverogers7050 9 ай бұрын
very nice explanation bhaiya
@Sumeet_100
@Sumeet_100 Жыл бұрын
Thank you for this video !!
@SukanyaGhosh-c4t
@SukanyaGhosh-c4t 11 ай бұрын
Thank You Bhaiya
@cursed_nerd
@cursed_nerd Жыл бұрын
Badhiya kaam kar rahe ho, see you soon
@GuruPrasadShukla
@GuruPrasadShukla Жыл бұрын
understood the approach sir thanks alot
@calmcrussader
@calmcrussader Ай бұрын
can we pass our counter integer by reference in the functions ?
@creepopsub2936
@creepopsub2936 11 күн бұрын
Understood! but how to get this approach in interview pressure. Such a Unique Solution ngl.
@saitehith6647
@saitehith6647 Жыл бұрын
Superb Explanation
@anshasati1920
@anshasati1920 6 ай бұрын
Understood Sir🥳
@TathagatTiwari-t6b
@TathagatTiwari-t6b Жыл бұрын
These types of questions always demotivate me... like how you can think of such kind of solution in an interview
@sarangkumarsingh7901
@sarangkumarsingh7901 9 ай бұрын
Nice lecture................
@hashcodez757
@hashcodez757 9 ай бұрын
understood Bhaiya!!
@NazeerBashaShaik
@NazeerBashaShaik 9 ай бұрын
Understood, thank you.
@atharva3571
@atharva3571 Жыл бұрын
I understood the problem
@grm642
@grm642 10 ай бұрын
Thank you😊
@YourCodeVerse
@YourCodeVerse Жыл бұрын
Understood✅🔥🔥
@gautamsaxena4647
@gautamsaxena4647 2 ай бұрын
understood bhaiya
@ShubhamKumar-uf3gc
@ShubhamKumar-uf3gc 6 ай бұрын
loved that bhaiya
@navdeepkumar9160
@navdeepkumar9160 Жыл бұрын
Great video
@satyamgupta4808
@satyamgupta4808 Жыл бұрын
very nice video
@ravalikatalks5285
@ravalikatalks5285 11 ай бұрын
thanks alot bhaiya
@mridulathya1201
@mridulathya1201 11 ай бұрын
Should'nt the line at 19:30 be "cnt += (mid - left + 1) - i "
@venup2813
@venup2813 Жыл бұрын
Understood brother❤️
@GhostVaibhav
@GhostVaibhav 10 ай бұрын
Understood🔥
@parasarora5869
@parasarora5869 Ай бұрын
Epic 🔥
@her_soulmate
@her_soulmate Жыл бұрын
Understood 🎉
@anshulrai6058
@anshulrai6058 2 ай бұрын
understood👍
@TheNullDeveloper
@TheNullDeveloper 6 ай бұрын
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
@infomania_by_ayush7901
@infomania_by_ayush7901 6 ай бұрын
Understood, but I am gonna need some time to implement this.
@infomania_by_ayush7901
@infomania_by_ayush7901 6 ай бұрын
Implemented.
Reverse Pairs | Hard Interview Question
32:26
take U forward
Рет қаралды 167 М.
Гениальное изобретение из обычного стаканчика!
00:31
Лютая физика | Олимпиадная физика
Рет қаралды 4,8 МЛН
3 Sum | Brute -  Better - Optimal with Codes
38:25
take U forward
Рет қаралды 375 М.
Burning Tree | GfG Problem of the Day | Binary Tree | BFS
18:19
Next Permutation - Intuition in Detail 🔥 | Brute to Optimal
28:15
take U forward
Рет қаралды 490 М.
Maximum Product Subarray - Best Intuitive Approach Discussed
20:27
take U forward
Рет қаралды 249 М.
How to Solve ANY LeetCode Problem (Step-by-Step)
12:37
Codebagel
Рет қаралды 330 М.
Find the Missing and Repeating Number | 4 Approaches 🔥
42:24
take U forward
Рет қаралды 191 М.
Hardy's Integral
13:47
Michael Penn
Рет қаралды 15 М.