Count Inversions in Array

  Рет қаралды 10,787

Code with Alisha

Code with Alisha

Күн бұрын

Пікірлер: 28
@venkatasriharsha4227
@venkatasriharsha4227 2 жыл бұрын
OMG 😱 never thought this would be that easy. Can't stop u appreciating for solving Gfg questions 👏. Keep posting, Thanks dude
@hariharibolll3459
@hariharibolll3459 Жыл бұрын
Dhanyawad MataJi. 🌸🙌🙏
@ashfaqmurshed503
@ashfaqmurshed503 Жыл бұрын
class Solution{ public: long long int count=0; long long int inversionCount(long long arr[], long long N) { mergesort(arr,0,N-1); return count; } long long int* mergesort(long long arr[],long long low, long long high) { if(low==high) { long long int* ans=new long long int[1]; ans[0]=arr[low]; return ans; } long long mid=(low+high)/2; long long int* left=mergesort(arr,low,mid); long long int* right=mergesort(arr,mid+1,high); return merge(left,right,mid-low+1,high-mid); } long long int* merge(long long int* left,long long int* right,int n, int m) { int i=0; int j=0; long long int* ans=new long long int[n+m+1]; int k=0; while(i
@gedelasivakrishna
@gedelasivakrishna 6 ай бұрын
Superb explination ! I always understand your explination in one go ,, thankyou
@DipsOfficial802
@DipsOfficial802 Жыл бұрын
Thank you for the great explanation, you gain a new subscriber.
@mlLearning490
@mlLearning490 Жыл бұрын
Thanku you so much Alisha ...Amazing explanation!!!😎
@darshankalathiya8667
@darshankalathiya8667 2 жыл бұрын
kitne dino se pata nai chal raha tha aaj cancept clear huaa thank you so much mem.
@nitinrai5053
@nitinrai5053 2 жыл бұрын
Such a nice explanation 🔥
@ghanshyampatil5850
@ghanshyampatil5850 Жыл бұрын
Great Explaination!!!
@sunnyseconds
@sunnyseconds Жыл бұрын
In python .....it is giving correct answer when count+=n-i+1.....in 52th line.........can you please tell me why
@rahul4142
@rahul4142 Жыл бұрын
Best Explanation.
@GhostRider....
@GhostRider.... Жыл бұрын
Thank you Mam ,nicely explained
@rasputin3571
@rasputin3571 2 жыл бұрын
Great Explaination
@gypsygirlkigypsylife
@gypsygirlkigypsylife Жыл бұрын
how count+=n-i;,how did u come up with this ??
@basavarajhadimani4493
@basavarajhadimani4493 2 жыл бұрын
While passing mid to mergearrays function why did you pass it as (mid-low+1) why not simply (mid+1) and also for the high too... Could you please explain that part?
@nageshwarmali9631
@nageshwarmali9631 Жыл бұрын
return merge(left,right,mid-low+1,high-mid); long long int* merge(long long int* left,long long int* right,int n, int m),lets see, actually n and m size of left and right array
@mayankmehra4370
@mayankmehra4370 Жыл бұрын
because its a length of a array
@bluegreen-
@bluegreen- Жыл бұрын
Hi Alisha, such an amazing explanation!! Btw there is another similar problem in leetcode called the reverse Pairs, I applied the same logic but i'm not able to get the output! class Solution { int count=0; public int reversePairs(int[] nums) { int N=nums.length; int a[]=mergesort(nums,0,N-1); return count; } public int[] mergesort(int arr[],int low,int high) { if(low==high) { int[] ans=new int[1]; ans[0]=arr[low]; return ans; } int mid=(low+high)/2; int[] left=mergesort(arr,low,mid); int[] right=mergesort(arr,mid+1,high); return merge(left,right,mid-low+1,high-mid); } public int[] merge(int[] left,int[] right,int n, int m) { int i=0; int j=0; int[] ans=new int[n+m+1]; int k=0; while(i
@sanachaitanyamotupalli4906
@sanachaitanyamotupalli4906 11 ай бұрын
if(left[i]>(2*right[j])) remove this
@amarshinde5863
@amarshinde5863 2 жыл бұрын
nice
@yatri6329
@yatri6329 2 жыл бұрын
Is this Q over Leetcode??
@probabilitycodingisfunis1
@probabilitycodingisfunis1 2 жыл бұрын
It is on hackerrank interview preparation kit , and geeksforgeeks, not sure about leetcode
@himanshusingh8693
@himanshusingh8693 Жыл бұрын
775. Global and Local Inversions(leetcode)
@harshkumaryadav3676
@harshkumaryadav3676 Жыл бұрын
😍🥰
@anshvashisht8519
@anshvashisht8519 Жыл бұрын
the thing you and i have same is number of tabs in chrome😂
@SajanKumar-ec2us
@SajanKumar-ec2us 11 ай бұрын
Explain why count + =n-i is ans
@AmanYadav-oe6wt
@AmanYadav-oe6wt Жыл бұрын
Its not working buddy.
@AmanYadav-oe6wt
@AmanYadav-oe6wt Жыл бұрын
Incorrect Output.
Count Inversions in an Array | Brute and Optimal
24:17
take U forward
Рет қаралды 187 М.
668. Kth Smallest Number in Multiplication Table Leetcode Daily Challenge
20:24
Викторина от МАМЫ 🆘 | WICSUR #shorts
00:58
Бискас
Рет қаралды 5 МЛН
КАК ДУМАЕТЕ КТО ВЫЙГРАЕТ😂
00:29
МЯТНАЯ ФАНТА
Рет қаралды 10 МЛН
小蚂蚁被感动了!火影忍者 #佐助 #家庭
00:54
火影忍者一家
Рет қаралды 30 МЛН
Counting inversions in an array
19:03
Techdose
Рет қаралды 91 М.
BREAKING Chess Drama As Niemann Rips Into Magnus Carlsen
8:25
Epic Chess
Рет қаралды 48 М.
2.6 - Counting Inversions in an Array in O(n log n) time via Divide and Conquer
19:27
Algorithms by Sharma Thankachan
Рет қаралды 10 М.
3 Sum Closest || Leetcode Daily Challenge || Code + Intuition + Example
13:36
COUNT INVERSIONS in an ARRAY | Leetcode | C++ | Java | Brute-Optimal
14:02
Chess Drama Continues Between Carlsen And Niemann
12:10
Epic Chess
Рет қаралды 17 М.
Викторина от МАМЫ 🆘 | WICSUR #shorts
00:58
Бискас
Рет қаралды 5 МЛН