Find the minimum distance between two numbers | GeeksforGeeks

Sdílet
Vložit
  • čas přidán 31. 03. 2016
  • Explanation for the article: www.geeksforgeeks.org/find-the...
    Practice Problem Online Judge: practice.geeksforgeeks.org/pro...
    This video is contributed by Harshit Jain.

Komentáře • 37

  • @amityadav-op4qv
    @amityadav-op4qv Před 5 lety

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

  • @divyeshbhartiya
    @divyeshbhartiya Před 4 lety +10

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

  • @avnishgupta8731
    @avnishgupta8731 Před 7 lety

    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
    @suryakantsapkal8242 Před 4 lety +1

    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.

  • @kasthurishravankumarhpc

    Thank you sir.

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

    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

  • @PraveenKumar-ft2kr
    @PraveenKumar-ft2kr Před 6 lety

    Really best👍👍👌

  • @youcan4913
    @youcan4913 Před 6 lety +2

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

  • @vishalmahavratayajula9658

    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

  • @sangnguyenn2367
    @sangnguyenn2367 Před rokem

    Thank you so much 🥰🥰🥰🥰🥰

  • @charchilgupta
    @charchilgupta Před 7 lety +1

    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  Před 7 lety

      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"

  • @hermesmercuriustrismegistu4841

    thx a lot

  • @SCRIPTSAG
    @SCRIPTSAG Před 4 lety

    This is enough practice for array

  • @shobhitchaturvediindia
    @shobhitchaturvediindia Před 8 lety +1

    Nice explanation

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

    Java HashMap will give o(n)

  • @dhruvmittal8018
    @dhruvmittal8018 Před rokem

    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
    @PradeepPant007 Před 3 lety

    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

  • @karandeeplamba8004
    @karandeeplamba8004 Před 4 lety

    k

  • @nanditabrahmbhatt62
    @nanditabrahmbhatt62 Před 2 lety

    //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
    @evolvingbackwards8637 Před 5 lety

    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
    @shenth27 Před 3 lety

    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.

  • @shreyaswaghmare7690
    @shreyaswaghmare7690 Před 5 lety

    Approach 2: Medium

  • @sunnybajaj4993
    @sunnybajaj4993 Před 3 lety

    Agar meri job lag gayi acchi to aapko laddu bhejuga

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

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