Find minimum difference between any two elements | GeeksforGeeks

Sdílet
Vložit
  • čas přidán 17. 04. 2016
  • Explanation for the article: www.geeksforgeeks.org/find-min...
    This video is contributed by Harshit Jain.
    Read More: www.geeksforgeeks.org/find-mi...

Komentáře • 21

  • @shenth27
    @shenth27 Před 3 lety +2

    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.

  • @slimyelow
    @slimyelow Před 3 lety

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

  • @MOHDMUJTABA1
    @MOHDMUJTABA1 Před 5 lety +1

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

  • @bhagyashreeswain1320
    @bhagyashreeswain1320 Před 2 lety

    Thanks a lot ..me ds abhi suru kar rahi hu mujhe isme bht dikat aarahi h but ur vdo make it simple.. ❤️

  • @noorqadri3507
    @noorqadri3507 Před 4 lety

    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

  • @professorsahab9210
    @professorsahab9210 Před 7 lety

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

  • @noorqadri3507
    @noorqadri3507 Před 4 lety +1

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

  • @professorsahab9210
    @professorsahab9210 Před 7 lety

    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?

  • @professorsahab9210
    @professorsahab9210 Před 7 lety

    what is int_max?

  • @professorsahab9210
    @professorsahab9210 Před 7 lety

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

    • @santhoshcts5
      @santhoshcts5 Před 7 lety

      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.

    • @professorsahab9210
      @professorsahab9210 Před 7 lety

      butt Dear Dev compiler show an error message to write this statement what is the solution of this program

    • @bhargavbp3765
      @bhargavbp3765 Před 4 lety

      @@professorsahab9210 use stdlib & limits.h header file

  • @shishpal1302
    @shishpal1302 Před 5 lety

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

    • @sairajdas6692
      @sairajdas6692 Před 5 lety

      No. In brute force the array is unsorted.

  • @reyou7
    @reyou7 Před 7 lety

  • @wecan2729
    @wecan2729 Před 3 lety

    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