This is a verified interview question from Gocomet. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Potential Attack Vector" covers key patterns like Arrays.
"Design an algorithm to detect potential attack vectors within a network. An attack vector in an array of keys is defined as a trio of indices (i, j, x) where keys[i] and keys[j] are both divisible by x. Given an array of integers keys, count the total number of possible attack vectors. For example, valid attack vectors for keys = [7, 2, 4] include: (0, 1) and keys[1] = 2 are both divisible by 1 (0, 2) and keys[0] = 7 and keys[2] = 4 are both divisible by 1 (2, 2) and keys[2] = 4 are both divisible by 4 (0, 2) and keys[2] = 4 are both divisible by 2 And others. Given a network of n keys and a 2-d array queries of dimensions * 2, each query provides an inclusive range [x <= queries[i][0] and x <= queries[i][1]]. Report an array of exactly q integers where the ith element of the array is the answer to the ith query."
Join thousands of developers practicing for Gocomet.