@@ -0,0 +1,947 @@
+public static int%5B%5D diagonalTraverse(int%5B%5D%5B%5D grid) %7B%0A  if (grid.length == 0 %7C%7C grid%5B0%5D.length == 0) %7B%0A    return new int%5B0%5D;%0A  %7D%0A  int count = grid.length * grid%5B0%5D.length;%0A  int cur = 0;%0A  int col = 0;%0A  int%5B%5D arr = new int%5Bcount%5D;%0A  boolean dir = false;%0A  while (cur %3C count) %7B%0A    int i = dir ? 0 : col;%0A    int j = dir ? col : 0;%0A%0A    if (dir) %7B%0A      // Traverse diagonally upwards%0A      while (j %3E= 0 %7C%7C i %3C grid.length) %7B%0A        if (isValid(grid, i, j)) %7B%0A          arr%5Bcur ++%5D = grid%5Bi%5D%5Bj%5D;%0A        %7D%0A        i ++;%0A        j --;%0A      %7D%0A    %7D else %7B%0A      // Traverse diagonally downwards%0A      while (i %3E= 0 && j %3C grid%5B0%5D.length) %7B%0A        if (isValid(grid, i, j)) %7B%0A          arr%5Bcur ++%5D = grid%5Bi%5D%5Bj%5D;%0A        %7D%0A        i --;%0A        j ++;%0A      %7D%0A    %7D%0A%0A    dir = !dir;%0A    col ++;%0A  %7D%0A%0A  return arr;%0A%7D%0A%0Apublic static boolean isValid(int%5B%5D%5B%5D grid, int i, int j) %7B%0A  return i %3C grid.length && j %3C grid%5B0%5D.length && i %3E= 0 && j %3E= 0;%0A%7D%0A

Add diagonal traverse