Simple Java Solution using BFS with comments and explanation
The idea is: \n1.  Create a list of int[] which contains x_coordinate, y_coordinate, and height of tree\n2.  Add all the trees which have height >1 to the list.
The idea is: \n1.  Create a list of int[] which contains ```x_coordinate, y_coordinate, and height of tree```\n2.  Add all the trees which have height >1 to the list.\n3.  Sort the given list based on their height, by using the Comparator class(or simply using Lambda expression from Java8)\n4.  Then traverse through each tree by using a BFS\n5.  In the BFS we are checking the distance needed to go to the tree from the current source coordinates(Since we have sorted the trees based on their height, our source coordinates will be different from the tree coordinates)\nFor eg: Our input is like this [[1,0,0],[1,0,0],[1,1,5]], then\ni) We have only 1 entry to be traversed, which is ```{x,y,height} = {2,2,5}```\nii) Once we have sorted the input trees, we are going to apply BFS\niii) Our source coordinates are (0,0) and our tree coordinates are (2,2) and then using BFS we are going to find out the shortest distance needed to to go from source to destination. \n\n\n```\nclass Solution {\n    int[][] dirs = new int[][]{{-1,0},{1,0},{0,-1},{0,1}};\n    public int cutOffTree(List<List<Integer>> forest) {\n        \n        //create a list of int[] {x, y, Height}\n        List<int[]> trees = new ArrayList<>();\n        for (int i = 0; i < forest.size(); i++) {\n            for (int j = 0; j < forest.get(0).size(); j++) {\n                int height = forest.get(i).get(j);\n                if (height > 1)\n                    trees.add(new int[]{i, j, height});\n            }\n        }\n        \n        //Sort all the trees based on their height\n        Collections.sort(trees, (a, b)->(a[2]-b[2]));\n        \n        //Run thru each test tree given to us\n        int res = 0, x = 0, y = 0;\n        for (int[] tree: trees) {\n        //Do a BFS traversal from current location(x,y) to that tree location(tree[0], tree[1])\n            int dist = bfs(forest, x, y, tree[0], tree[1]);\n            if (dist < 0) \n                return -1;\n            else\n            {\n                res = res + dist;\n                x = tree[0];\n                y = tree[1];\n            }\n        }\n        return res;\n    }\n    \n    private int bfs(List<List<Integer>> forest, int x, int y, int tx, int ty) \n    {\n        //A typical BFS approach that we use\n        int m = forest.size(), n = forest.get(0).size();\n        Queue<int[]> queue = new LinkedList<>();\n        boolean[][] visited = new boolean[m][n];\n        \n        //Add the current source coordinates to the queue and mark it as visited\n        queue.add(new int[]{x, y});\n        visited[x][y] = true;\n        \n        int dist = 0;\n        \n        while (!queue.isEmpty()) {\n            int size = queue.size();\n           \n            for (int j = 0; j < size; j++) {\n                int[] cur = queue.poll();\n                \n                 //If we have reached the tree at (tx,ty) through traversal then that means we can return the distance covered from (x,y) to (tx,ty)\n                if (cur[0] == tx && cur[1] == ty) \n                    return dist;\n                \n                //Traverse in all 4 directions and then process it if it meets the conditions\n                for (int i = 0; i < 4; i++) \n                {\n                    int nx = cur[0]+dirs[i][0];\n                    int ny = cur[1]+dirs[i][1];\n                    \n                    if (nx >= 0 && nx < m && ny >= 0 && ny < n && \n                        !visited[nx][ny] && forest.get(nx).get(ny) >= 1)\n                    {\n                      visited[nx][ny] = true;\n                      queue.add(new int[]{nx, ny});\n                   }\n                }\n            }\n            dist++;\n        }\n        return -1;\n    }\n}\n```
['Breadth-First Search', 'Java']