forked from architsingla13/InterviewBit-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAntiDiagonals.java
More file actions
46 lines (37 loc) · 967 Bytes
/
AntiDiagonals.java
File metadata and controls
46 lines (37 loc) · 967 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package Array;
import java.util.ArrayList;
/**
* Author - archit.s
* Date - 21/08/18
* Time - 11:51 PM
*/
public class AntiDiagonals {
public ArrayList<ArrayList<Integer>> diagonal(ArrayList<ArrayList<Integer>> A) {
ArrayList<ArrayList<Integer>> result = new ArrayList<>();
int n = A.size();
int col = 0;
while(col < n){
result.add(new ArrayList<>());
int i = 0, j = col;
while(i < n && j >= 0){
result.get(col).add(A.get(i).get(j));
i++;
j--;
}
col++;
}
int row = 1;
while(row < n){
result.add(new ArrayList<>());
int i = row, j = n-1;
while(i < n && j >= 0){
result.get(col).add(A.get(i).get(j));
i++;
j--;
}
col++;
row++;
}
return result;
}
}