wild Card Entry
bruteCoder
java
2 years ago
874 B
10
Indexable
class Solution
{
public int[] antiDiagonalPattern(int[][] mat)
{
// Code here
int row = 0;
int n = mat.length;
int m = mat[0].length;
int[] out = new int[n*m];
int o = 0;
int itr = 0;
while (itr < n + m) {
int col = 0;
if (itr >= m) {
row+=1;
col = m - 1;
} else col = itr;
int frow = row;
while (isValid(frow, col, mat)) {
out[o++] = mat[frow][col];
// System.out.print(mat[frow][col] + " ");
frow += 1;
col -= 1;
}
itr += 1;
}
return out;
}
public static boolean isValid(int i, int j , int[][] matrix)
{
return (i>=0 && j>=0 && i< matrix.length && j<matrix[0].length);
}
}Editor is loading...
Leave a Comment