private int dfs(int[][] matrix, int[][] scoreBoard,
                    boolean[][] visiting,
                    int startX, int startY ){


        int currentValue = matrix[startX][startY];
        visiting[startX][startY] = true;

        int maxLength=1;
        for (int i=0; i<dx.length; i++){
            int nextX= startX + dx[i];
            int nextY= startY + dy[i];
            if (nextX<0 || nextX > matrix.length-1 || nextY<0 || nextY>matrix[0].length-1){
                continue;
            }
            if (matrix[nextX][nextY] > currentValue
                && !visiting[nextX][nextY] ){
                int length=0;
                if (scoreBoard[nextX][nextY] !=0){
                    length = 1+scoreBoard[nextX][nextY];
                }
                else{
                    length = 1+ dfs(matrix, scoreBoard, visiting,  nextX, nextY );
                }

                if (length > maxLength){
                    maxLength = length;
                }
            }


        }

        visiting[startX][startY] = false;
        scoreBoard[startX][startY] = maxLength;
        return maxLength;
    }