Explanation for the article: www.geeksforgeeks.org/find-the... Practice Problem Online Judge: practice.geeksforgeeks.org/pro... This video is contributed by Harshit Jain.
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.
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
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
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).
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"
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
//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)
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.
In the 2nd method , 1st for loop ,why i
When min_dist is equal to 1,can we break the loop there itself? Coz min_dist can not be less than 1.
correct .
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.
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.
Thank you sir.
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
Really best👍👍👌
Sir i think some modification should be done in the second program. after storing the index in prev u should increament i =i+1;
I also noticed same
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
Thank you so much 🥰🥰🥰🥰🥰
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).
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"
thx a lot
This is enough practice for array
Nice explanation
Thank you, Shobhit!
Java HashMap will give o(n)
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
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
k
//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)
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
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.
Approach 2: Medium
Agar meri job lag gayi acchi to aapko laddu bhejuga
presentation skills are pathetic actually. Presenter is just reading the slides.