Find the minimum distance between two numbers | GeeksforGeeks

Explanation for the article: www.geeksforgeeks.org/find-the...
Practice Problem Online Judge: practice.geeksforgeeks.org/pro...
This video is contributed by Harshit Jain.

Пікірлер: 37

  • @amityadav-op4qv
    @amityadav-op4qv5 жыл бұрын

    In the 2nd method , 1st for loop ,why i

  • @divyeshbhartiya
    @divyeshbhartiya4 жыл бұрын

    When min_dist is equal to 1,can we break the loop there itself? Coz min_dist can not be less than 1.

  • @abhijeet2153

    @abhijeet2153

    3 жыл бұрын

    correct .

  • @avnishgupta8731
    @avnishgupta87317 жыл бұрын

    Hi Can't we solve it using the stack as to count how many we have pop after one of the value we are able to find out.

  • @suryakantsapkal8242
    @suryakantsapkal82424 жыл бұрын

    Hey, thanks for this video.!! Method 2 looks good for all the arrays which contains X and Y values. You also need to handle the scenario where if array does not contain any of the X or Y value then min distance should be 0.

  • @rithikroosen2416
    @rithikroosen24164 жыл бұрын

    public static void main(String[] args) { int arr[]={3,5,4,2,6,5,6,6,5,4,8,3}; minimumdistance(arr); // TODO Auto-generated method stub } static void minimumdistance(int a1[]) { int count=1,k=0,q=0,i=1,j=0; int size=a1.length; int n1=0,n=0; Scanner obj= new Scanner(System.in); System.out.println("Enter the first number in an array "); n1=obj.nextInt(); System.out.println("Enter the second number in an array "); n=obj.nextInt(); for(i=0;i

  • @youcan4913
    @youcan49136 жыл бұрын

    Sir i think some modification should be done in the second program. after storing the index in prev u should increament i =i+1;

  • @mukeshsinghdance7332

    @mukeshsinghdance7332

    4 жыл бұрын

    I also noticed same

  • @kasthurishravankumarhpc
    @kasthurishravankumarhpc5 жыл бұрын

    Thank you sir.

  • @PraveenKumar-ft2kr
    @PraveenKumar-ft2kr6 жыл бұрын

    Really best👍👍👌

  • @vishalmahavratayajula9658
    @vishalmahavratayajula96584 жыл бұрын

    At 7:55 you said we should not find variable x, but that is not correct. We can still find it and update the prev. That's how you would get the min distance for same like this 61234678. where 6 and 8 are the 2 given no.s

  • @charchilgupta
    @charchilgupta7 жыл бұрын

    Hello GFG , I am a big fan of you guys and really appreciate your hard work. Just a suggestion - Could you please make your videos little bit more interesting.....by interesting I mean the way of presentation can be improved ...(like using videoscribe or other animations and also the tone of speaker can be more dynamic).

  • @GeeksforGeeksVideos

    @GeeksforGeeksVideos

    7 жыл бұрын

    Thank you, Charchil! We are trying out different ways of presentation. Soon, you will see different kinds of videos on our channel. And, if you are interested in contributing to our channel, please drop us an email at "videos@geeksforgeeks.org"

  • @sangnguyenn2367
    @sangnguyenn2367 Жыл бұрын

    Thank you so much 🥰🥰🥰🥰🥰

  • @hermesmercuriustrismegistu4841
    @hermesmercuriustrismegistu48414 жыл бұрын

    thx a lot

  • @SCRIPTSAG
    @SCRIPTSAG4 жыл бұрын

    This is enough practice for array

  • @shobhitchaturvediindia
    @shobhitchaturvediindia8 жыл бұрын

    Nice explanation

  • @GeeksforGeeksVideos

    @GeeksforGeeksVideos

    7 жыл бұрын

    Thank you, Shobhit!

  • @jiniamitra7593
    @jiniamitra75934 жыл бұрын

    Java HashMap will give o(n)

  • @dhruvmittal8018
    @dhruvmittal8018 Жыл бұрын

    i'm trying to run same code but don't know why this is giving me wrong answer class Solution{ public: int minDist(int a[], int n, int x, int y) { int i; int prev; int min_dis=INT_MAX; for(i=0;i

  • @PradeepPant007
    @PradeepPant0073 жыл бұрын

    Method 1- More Simplified class Solution { int minDist(int a[], int n, int x, int y) { int mindis=Integer.MAX_VALUE; boolean g=false; for(int i=0;i

  • @nanditabrahmbhatt62
    @nanditabrahmbhatt622 жыл бұрын

    //alternate solution public class mindistance { public static void main(String[] args) { int a[]={1,2,3,2,4,6,1}; int index1=-1,index2=-1,len=Integer.MAX_VALUE; for(int i=0;i-1&&index2>-1) { if (Math.abs(index1-index2)

  • @evolvingbackwards8637
    @evolvingbackwards86375 жыл бұрын

    why cant we use this??????? #include using namespace std; int main(){ int a[] = {2, 5, 3, 5, 4, 4, 2, 3}; int differ=0 , pos1=0 , pos2=0 , final_diff=0; int num1 = 3 , num2 = 2; for(int i=0;ipos1){ differ = pos2-pos1; } if(pos1>pos2){ differ = pos1-pos2; } if(final_diff > differ || final_diff==0){ final_diff = differ; } } cout

  • @shenth27
    @shenth273 жыл бұрын

    Thanks for the video. Just one suggestion though, going through the lecture notes before the code walkthrough is unnecessary, it's just repeating the same thing. All we care about is the code - how the logic is written.

  • @karandeeplamba8004
    @karandeeplamba80044 жыл бұрын

    k

  • @shreyaswaghmare7690
    @shreyaswaghmare76905 жыл бұрын

    Approach 2: Medium

  • @sunnybajaj4993
    @sunnybajaj49933 жыл бұрын

    Agar meri job lag gayi acchi to aapko laddu bhejuga

  • @harshil9059
    @harshil90594 жыл бұрын

    presentation skills are pathetic actually. Presenter is just reading the slides.