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.
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
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?
which means the integer.max_value in any programming language . idea is to keep it as high as possible so that when you find (arr[i+1] - arr[i] ) , for the first time will be always less than this maximum value and hence this result will be stored in diff and used for subsequent comparisons.
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.
There Could be a better solution if we are using hashmap can be done in O(n) time and O(n) space
funny how he says the simplest method and I'm still don't get it.
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
How would I output an array with all numbers with the minimum difference.
Thanks a lot ..me ds abhi suru kar rahi hu mujhe isme bht dikat aarahi h but ur vdo make it simple.. ❤️
class Solution{
public:
int minimum_difference(vectornums)
{
sort(nums.begin(),nums.end());
int mn=INT_MAX;
int n=nums.size();
for(int i=0;i
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?
In the brute force approach, you aren't taking adjacent pairs. it will lead to the wrong answer.
No. In brute force the array is unsorted.
.if you already create a video on min heap or max so please send those totorial link
what is int_max?
Very large value equivalent to infinity
Largest value integer data type can hold
pow(2,31)-1 or 2 to the power 31 minus 1
plz Dear Teacher answer about this statement(int diff=INT_MAX;)
which means the integer.max_value in any programming language . idea is to keep it as high as possible so that when you find (arr[i+1] - arr[i] ) , for the first time will be always less than this maximum value and hence this result will be stored in diff and used for subsequent comparisons.
butt Dear Dev compiler show an error message to write this statement what is the solution of this program
@@professorsahab9210 use stdlib & limits.h header file