-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCanRotationAchieveArray.java
More file actions
33 lines (32 loc) · 1003 Bytes
/
CanRotationAchieveArray.java
File metadata and controls
33 lines (32 loc) · 1003 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
public class CanRotationAchieveArray {
public static void main(String[] args) {
//the problem asks if we can achieve the given array after rotating the original array any number of times
int[][] a = {{0,0,0},{0,1,0},{1,1,1}};
int[][] b = {{1,1,1},{0,1,0},{0,0,0}};
System.out.println(findRotation(a,b));
}
public static boolean findRotation(int[][] a, int[][] b) {
int n=a.length;
int c90=0,c180=0,c270=0,c0=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(b[i][j]==a[n-j-1][i])
c90++;
if(b[i][j]==a[n-i-1][n-j-1])
c180++;
if(b[i][j]==a[j][n-i-1])
c270++;
if(b[i][j]==a[i][j])
c0++;
}
}
if(c90==n*n||c270==n*n||c180==n*n||c0==n*n) {
return true;
}
else {
return false;
}
}
}