int calculateMinDist(int a[], int x, int y) {
		int limit = -(a.length + a.length);
		int xIndex = limit, yIndex = limit, min = 99999, xAltIndex = limit, yAltIndex = limit;
		boolean xfound = false, yfound = false;
		
		//Loop through the array
		for (int i = 0; i < a.length; i++) {
		
			//Check if the current number is 'x'
			if (a[i] == x) {	
				if(yIndex == limit)
				{
					xIndex = i;
					continue;
				}
				else if(i - yIndex < min)
				{
					xIndex = i;
					min = xIndex - yIndex;
				}
				else if(i - yAltIndex < min)
				{
					xIndex = i;
					min = xIndex - yAltIndex;
				}
				else
				{
					xAltIndex = i;
				}
			} 
			
			//Check if the current number is 'y'
			else if (a[i] == y) {
				if(xIndex == limit)
				{
					yIndex = i;
					continue;
				}
				else if(i - xIndex < min)
				{
					yIndex = i;
					min = yIndex - xIndex;
				}
				else if(i - xAltIndex < min)
				{
					yIndex = i;
					min = yIndex - xAltIndex;
				}
				else
				{
					yAltIndex = i;
				}
			} 
		}
		return min;
	}