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
Please watch our new video on the same topic: ruclips.net/video/AseUmwVNaoY/видео.html
this link take u to the same video we are watching
@@namannema3349 thats what recursion means
Nowadaya strivers voice has become so calm and soft 😅❤
True...as compared to his previous vdos 😂
😂
@@anuradha3868 same thought 😂
abe mic kharap tha pehle😂
Best count inversion video on RUclips, your method of teaching is very best that it gets me understand very easily 🌟🌟🌟
this is the best playlist in world. thank you stiver for your effort.
The best count inversion video on RUclips.. Thanks a lot Raj.. stay blessed❤
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 ❤
whats the complexity of your solution?
can you share it?
@@bishakhdutta8427 same as merger sort merge algorithm
Understood! Super amazing explanation as always, thank you very very very much for your effort!!
Completed the playlist. This was the best recursion playlist I ever went through. Thanks a lot Striver.
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
Striver your voice is very soothing and calm bro ❤.... I use it to sleep at night AND study... and I don't feel sleepy
Understood it very well
Thanks for this amazing series
So much crystal clear!!!!Thank youu❤
This is the best explanation I've ever got.
Understood
THE BEST EXPLANATION
Excellent playlist 👌 👏 ❤
your problem solving approach explanation is superb
As usual your teaching jus made coding much easier than it is bruh!! Waiting for Binary Search series bruh!!!!
Best explanation ever for this problem
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
Thoroughly enjoyed the problem!!
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:>)
UNDERSTOOD SIR ! GREAT EXPLAINATION
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.
awesome as always!!!!🤩
i just imagine if all the problems would be available on this channel in future
OMG Bawal explanation Striver Bhaiya.😃
Great explanation!!
Superb logic, Understood!!!
Thank you for this video !!
Understood amazing explanation
Really it was a great series Striver.🔥🔥
understood the approach sir
thanks alot
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;
}
loved the optimal solution, intuition op!
thanks striver for making a complex question into very easy question
🤗
Superb Explanation
Understood, thank you.
Best explanation ever
thank you so much for watching
just wow explanation
All i can say is Thankyou so much ❤🙌
I was struggling with the solution but as soon as you mentioned merge sort it clicked in my mind
very nice explanation bhaiya
I am happy with the brute force now I will see optimal 1 week before interview bcz University exams are in this month
Did anyone ask you?
Amazing I solved two questions using the same logic.
understood Bhaiya!!
Great video
// 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
Thank you😊
Nice lecture................
Badhiya kaam kar rahe ho, see you soon
Thank You Bhaiya
Understood Sir🥳
understood!
def merge(arr,l,mid,h):
temp=[]
i=l
j=mid+1
cnt=0
while i
understood!!!
loved that bhaiya
Understood brother❤️
Understood✅🔥🔥
thanks alot bhaiya
very nice video
so aweesome
Thanks 😊👍
Understood thats great...
The way he said wow! Uff in love with the voice
thanks mate
Understood 🎉
Thanks
Understood🔥
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.
understood 👍👍
UNDERSTOOD
Understood!
thank u striver
I understood the problem
Thank u bhai
Understood sir
understood :)
Understood, but I am gonna need some time to implement this.
Implemented.
Understood :)
understood.
Understood...!!!!
understood
Global vs Local
In Global variables values updated dynamically but in local variables we need to pass updated values (manually) to subsequent functions
These types of questions always demotivate me... like how you can think of such kind of solution in an interview
Understood
awesome
13:05 the kind of excitement I want while learning DSA.
didn't understand much but will try again
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
Hi Striver , is creating static variables in interview is a bad practice?
Is it fine to pass variables by reference?Or should we avoid that too in the interviews?
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
can anybody pls explain why we cant/ should'nt declare the 'cnt' variable globally ?
Gold
cleared
🔥🔥🔥🔥🔥
I used an array of 1 size and passed it by reference to count the pairs.
00:00
❤❤
can i solve this question using pbds
Time Stamps:
--------------------------------------------------
00:40 Problem Statement