Hey guys I will explain the question below.
keys = list of integers I have to find max degree of divisibility of elements in keys. But When I calculate the degree of divisibility I should just consider the keys element. for example:
keys = [2,4,8,2]
2 = [2,2] degree of divisibility is 2
4 = [2,4,2] degree of divisibility is 3
8 = [2,4,8,2] degree of divisibility is 4 so we choose 8 with 4 degrees of divisibility.
after that we have to calculate
if maxDegreeOfDivisibility(4 in our case) * 10^5 < validityPeriod* instructionCount then its
true.
and we return 1 and 4*10^5. I hope I explain the question if u guys have any questions about the question :D I can answer.
public static List<Integer> encryptionValidity(int instructionCount, int validityPeriod,
List<Integer> keys) {
List<Integer> result = Arrays.asList(0, 0);
Map<Integer, Integer> degreeOfDivisibilityCache = new HashMap<>();
for (int i: keys) {
Integer degreeOfDivisibility = degreeOfDivisibilityCache.getOrDefault(i, -1);
if (degreeOfDivisibility == -1) {
int count = 0;
for (int j : keys) {
if (j > 0 && i % j == 0) {
count++;
}
}
degreeOfDivisibilityCache.put(i, count);
}
}
int maxDegreeOfDivisibility = degreeOfDivisibilityCache.values().stream()
.max(Comparator.comparingInt(Integer::intValue)).orElse(0);
int s = maxDegreeOfDivisibility * 10000;
result.set(1, s);
BigInteger ic = BigInteger.valueOf(instructionCount);
BigInteger a = ic.multiply(BigInteger.valueOf(validityPeriod));
if (a.compareTo(BigInteger.valueOf(s)) > 0) {
result.set(0, 1);
}
return result;
}