int sliding(int diff,int arr[],int n) { //how many pairs have absolute diff less than or //equal to diff int j =0; int count=0; for(int i=1;idiff)j++; count+=i-j; } return count; } int kthDiff(int arr[], int n, int k) { sort(arr,arr+n); int high = arr[n-1]-arr[0]; int low =INT_MAX; for(int i=1;i
Pinned by Code with Alisha @probabilitycodingisfunis1 1 year ago (edited) int sliding(int diff,int arr[],int n) { //how many pairs have absolute diff less than or //equal to diff int j =0; int count=0; for(int i=1;idiff))j++; if(j==i) continue; count+=i-j; } return count; }
I dont know how could I thank you , I litterally read others solutions on LC for 1 hr , watched 4-5 videos on this then I got this ... Perfectly explained and the detailed dry run was very helpful
Hey Alisha, a great solution!! 1 QUERY: In this Binary search approach that you have followed, lets suppose you get the required answer but is it necessary that the difference that you get in answer will be actually a difference between a pair of values of input array?? Like it may be possible that the diff that we got in ans using binary search might not a gettable using diff of any 2 array numbers....
There is no real performance hit when you make 0 as the lower bound of your solution space in the binary search. Better cognitive complexity of the code.
Your explanation is great. But kindly don't repeat basic stuffs twice. Would be great if you keep it little shorter. Just a suggestion. But You are excellent.
int sliding(int diff,int arr[],int n)
{
//how many pairs have absolute diff less than or
//equal to diff
int j =0;
int count=0;
for(int i=1;idiff)j++;
count+=i-j;
}
return count;
}
int kthDiff(int arr[], int n, int k)
{
sort(arr,arr+n);
int high = arr[n-1]-arr[0];
int low =INT_MAX;
for(int i=1;i
Pinned by Code with Alisha
@probabilitycodingisfunis1
1 year ago (edited)
int sliding(int diff,int arr[],int n)
{
//how many pairs have absolute diff less than or
//equal to diff
int j =0;
int count=0;
for(int i=1;idiff))j++;
if(j==i) continue;
count+=i-j;
}
return count;
}
I could appreciate for one thing that u always teach tough problems, hats off to u
I dont know how could I thank you , I litterally read others solutions on LC for 1 hr , watched 4-5 videos on this then I got this ... Perfectly explained and the detailed dry run was very helpful
one of the most beautifully explained solutions❤❤❤
Brilliant explanation and dry run of the case as usual. Thanks for this
Thanks for in detail explanation ❤
Superb Explanation!!
Your explanations are great. Thanks a lot!
Beautiful explanation and it was easy to understand.
problem of the day?? leetcode
@@Facts-oo8dvyeah
@@Facts-oo8dv yup
very clearly explanation, thank you very Alisha for sharing
Thanks for your awesome explanation, I was stuck in this problem since morning.
Welcome
Again a great explaination of a relatively tougher problem,thanks a lot mam..Keep making such wonderful videos
Thank you so much . I was not able to find any approach for this problem
Welcome
nice explanation
Total numbers of pairs will be nC2 = n * (n-1)/2 = 4 * 3 / 2 = 6
Thank you so much for this type of very helpful videos ...
Nice explanation. Thank you.
Thank you good explaination
Hey Alisha, a great solution!!
1 QUERY: In this Binary search approach that you have followed, lets suppose you get the required answer but is it necessary that the difference that you get in answer will be actually a difference between a pair of values of input array??
Like it may be possible that the diff that we got in ans using binary search might not a gettable using diff of any 2 array numbers....
Thank You So Much for the Explanation, This is indeed the best approach one can explain, Major Appreciations!!
Thank you so much
Great explanation !!! ☺️☺️☺️
well explained :)
Nicely explained👍
Thank you ma'am. Nicely explained
Thank you so much
Thanks
Awesome explanation sister was able to learn a lot keel doing more videos🔥👍
Awesome example
there is another approach for this problem (Trial and Error was it?) , can you please explain with that approach too?
Great explanation! thank you.
Such a great explanation mam
Really great
Hatts off too you mam🙌🙌😍
Thank you
was waiting for this video !
Hii, can you please explain: the mid we are calculating will always be the difference of any pair.
little long video, but you have explained really well , thanks
can you please upload today's POTD solution
The total number of possible pairs are: (n*(n-1))/2
how come is n = 3?
There is no real performance hit when you make 0 as the lower bound of your solution space in the binary search. Better cognitive complexity of the code.
Your explanation is great. But kindly don't repeat basic stuffs twice. Would be great if you keep it little shorter. Just a suggestion. But You are excellent.
Brute Force TC will be : N^2(log N)🙂
Not a good explaination
sexy explaination