Here is my implementation, using bit instead of array for speed up

public class Solution {
private int helper(int ind, int max, int taken) {
if (ind < 2) return 1;
int res = 0;
for (int i = max; i >= 1; i--) {
if ((taken & (1 << i)) == 0 && (i % ind == 0 || ind % i == 0)) {
res += helper(ind - 1, max, taken ^ (1 << i));
}
}
return res;
}
public int countArrangement(int N) {
return helper(N, N, 0);
}
}