Try two methods. One is BFS with the queue. The other is DFS with recursion. import java.util.*; public class Solution { // bfs with queue public final int[][] direction = {{-1,0},{0,1},{1,0},{0,-1}}; public int movingCount(int threshold, int rows, int cols) { Queue<Cell> q...