public static int findMinimumDistance(int []input, int x, int y){
        int prev =-1; int i=0;
        int privIndex = -1;
        int minDistance = Integer.MAX_VALUE;

        //find first item which matches either of x or y
        for(;i<input.length; i++) {
            if(input[i] == x || input[i] ==y) {
                privIndex = i;
                //since we are breaking increase the i
                prev = input[i++];
                break;
            }
        }

        //keep goinf to the right and check if we have anything equal to x or y
        for( ;i<input.length;i++){
            if(input[i] ==x || input[i] ==y) {
                //if it is not equal to prev item
                if(input[i]!=prev){
                    //update the minimum distance if required
                    if(minDistance > i-privIndex) {
                        minDistance = i-privIndex;
                    }
                } else {
                    //make this index as privIndex
                    privIndex = i;
                }
            }
        }

        return minDistance;

    }