Find minimum difference between any two elements | GeeksforGeeks

preview_player
Показать описание

This video is contributed by Harshit Jain.

Рекомендации по теме
Комментарии
Автор

The whole point of spending nlogn time sorting is to reduce the time complexity when doing the actual comparison, because now you only need to compare the adjacent numbers unlike the first method which compares each number with every other numbers.

shenth
Автор

There Could be a better solution if we are using hashmap can be done in O(n) time and O(n) space

MOHDMUJTABA
Автор

How would I output an array with all numbers with the minimum difference.

slimyelow
Автор

I have to find the largest gap between two consecutive numbers in a list. (ai -- ai --i )
This is what I have so far (python)
def largestGap L:
maxVal = L(i):
for i in range (0):
L(i)=L(i) + L(i-n)
if maxVal > i :
maxVal == i
return maxVal


I don't even know if this is right, so confused, someone please help

noorqadri
Автор

your totorial is very good
so dear teacher i request you to create a totorial on min heap and max heap that check the array elemnt is fulfil the condition of min heap or not?

professorsahab
Автор

funny how he says the simplest method and I'm still don't get it.

noorqadri
Автор

.if you already create a video on min heap or max so please send those totorial link

professorsahab
Автор

In the brute force approach, you aren't taking adjacent pairs. it will lead to the wrong answer.

shishpal
Автор

class Solution{
public:
int
{
sort(nums.begin(), nums.end());
int mn=INT_MAX;
int n=nums.size();
for(int i=0;i<n-1;i++)
{
mn=min(mn, nums[i+1]-nums[i]);
}
return mn;
}
};

wecan
Автор

plz Dear Teacher answer about this statement(int diff=INT_MAX;)

professorsahab