Find the minimum distance between two numbers | GeeksforGeeks

  Рет қаралды 65,330

GeeksforGeeks

GeeksforGeeks

8 жыл бұрын

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-op4qv 5 жыл бұрын
In the 2nd method , 1st for loop ,why i
@rithikroosen2416
@rithikroosen2416 4 жыл бұрын
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
@divyeshbhartiya
@divyeshbhartiya 4 жыл бұрын
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 .
@suryakantsapkal8242
@suryakantsapkal8242 4 жыл бұрын
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.
@avnishgupta8731
@avnishgupta8731 7 жыл бұрын
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.
@youcan4913
@youcan4913 7 жыл бұрын
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
@PraveenKumar-ft2kr
@PraveenKumar-ft2kr 6 жыл бұрын
Really best👍👍👌
@kasthurishravankumarhpc
@kasthurishravankumarhpc 5 жыл бұрын
Thank you sir.
@vishalmahavratayajula9658
@vishalmahavratayajula9658 4 жыл бұрын
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
@charchilgupta 7 жыл бұрын
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
@hermesmercuriustrismegistu4841 4 жыл бұрын
thx a lot
@SCRIPTSAG
@SCRIPTSAG 4 жыл бұрын
This is enough practice for array
@shobhitchaturvediindia
@shobhitchaturvediindia 8 жыл бұрын
Nice explanation
@GeeksforGeeksVideos
@GeeksforGeeksVideos 7 жыл бұрын
Thank you, Shobhit!
@jiniamitra7593
@jiniamitra7593 4 жыл бұрын
Java HashMap will give o(n)
@PradeepPant007
@PradeepPant007 3 жыл бұрын
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
@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
@nanditabrahmbhatt62
@nanditabrahmbhatt62 2 жыл бұрын
//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)
@karandeeplamba8004
@karandeeplamba8004 4 жыл бұрын
k
@evolvingbackwards8637
@evolvingbackwards8637 5 жыл бұрын
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 3 жыл бұрын
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 5 жыл бұрын
Approach 2: Medium
@harshil9059
@harshil9059 4 жыл бұрын
presentation skills are pathetic actually. Presenter is just reading the slides.
@sunnybajaj4993
@sunnybajaj4993 3 жыл бұрын
Agar meri job lag gayi acchi to aapko laddu bhejuga
Find the missing number | GeeksforGeeks
7:47
GeeksforGeeks
Рет қаралды 129 М.
Jumping off balcony pulls her tooth! 🫣🦷
01:00
Justin Flom
Рет қаралды 28 МЛН
ОБЯЗАТЕЛЬНО СОВЕРШАЙТЕ ДОБРО!❤❤❤
00:45
Опасность фирменной зарядки Apple
00:57
SuperCrastan
Рет қаралды 12 МЛН
GeeksForGeeks| Minimum Distance Between Two Numbers
21:37
Mathematics
Рет қаралды 42
Jordan Peterson - Do You Want To Have A Life? Or Be Exceptional At One Thing?
5:12
Bite-sized Philosophy
Рет қаралды 2,4 МЛН
How to Respond to Different Situations in English
10:48
Learn English with Bob the Canadian
Рет қаралды 10 М.
Union and Intersection of two sorted arrays | GeeksforGeeks
10:02
GeeksforGeeks
Рет қаралды 147 М.
Floor and Ceiling in a sorted array | GeeksforGeeks
10:37
GeeksforGeeks
Рет қаралды 21 М.
Jumping off balcony pulls her tooth! 🫣🦷
01:00
Justin Flom
Рет қаралды 28 МЛН