private int DFS(int input[][],int i,int j,boolean visited[][],int lastNum){
		if(i >= input.length || i < 0 || j < 0 || j >= input[0].length){
			return 0;
		}
		if(visited[i][j]){
			return 0;
		}
		if(lastNum != -10000 && input[i][j] + 1 != lastNum){
			return 0;
		}
		visited[i][j] = true;
		
		int r1 = DFS(input,i+1,j,visited,input[i][j]);
		int r2 = DFS(input,i-1,j,visited,input[i][j]);
		int r3 = DFS(input,i,j+1,visited,input[i][j]);
		int r4 = DFS(input,i,j-1,visited,input[i][j]);
		visited[i][j] = false;
		return Math.max(Math.max(r1, r2), Math.max(r3,r4)) + 1;
	}
Find the length of the longest chain of consecutive integers in an unsorted 2D square array (non-diagonal)
src/com/interview/multiarray/LongestConsecutiveIntegerInUnsorted2DArray.java