Find minimum difference between any two elements | GeeksforGeeks

Поділитися
Вставка
  • Опубліковано 1 жов 2024
  • Explanation for the article: www.geeksforgee...
    This video is contributed by Harshit Jain.
    Read More: www.geeksforge...

КОМЕНТАРІ • 21

  • @shenth27
    @shenth27 3 роки тому +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.

  • @MOHDMUJTABA1
    @MOHDMUJTABA1 5 років тому +1

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

  • @noorqadri3507
    @noorqadri3507 4 роки тому +1

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

  • @noorqadri3507
    @noorqadri3507 4 роки тому

    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

  • @slimyelow
    @slimyelow 3 роки тому

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

  • @bhagyashreeswain1320
    @bhagyashreeswain1320 3 роки тому

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

  • @reyou7
    @reyou7 7 років тому

  • @wecan2729
    @wecan2729 3 роки тому

    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

  • @professorsahab9210
    @professorsahab9210 7 років тому

    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?

  • @shishpal1302
    @shishpal1302 5 років тому

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

    • @sairajdas6692
      @sairajdas6692 5 років тому

      No. In brute force the array is unsorted.

  • @professorsahab9210
    @professorsahab9210 7 років тому

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

  • @professorsahab9210
    @professorsahab9210 7 років тому

    what is int_max?

  • @professorsahab9210
    @professorsahab9210 7 років тому

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

    • @santhoshcts5
      @santhoshcts5 7 років тому

      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 7 років тому

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

    • @bhargavbp3765
      @bhargavbp3765 4 роки тому

      @@professorsahab9210 use stdlib & limits.h header file