FastPrepCount Attack Vectors by Divisor Range
Problems/Count Attack Vectors by Divisor Range

Count Attack Vectors by Divisor Range

Visa logoVisa● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The Visa OA image defines ordered attack vectors, explicitly allows equal indices, and gives range queries over the divisor x. The report does not label an employment category, so this record uses the full-time default. We supply numeric limits and the function name.

An attack vector for an integer array keys is a triple (i, j, x) such that both keys[i] and keys[j] are divisible by x.

The pair (i, j) is ordered, and i may equal j. For each inclusive query [left, right], return the total number of attack vectors whose divisor satisfies left <= x <= right.

Return one 64-bit answer per query, in the original query order.

Function

countAttackVectors(keys: int[], queries: int[][]) → long[]

Examples

Example 1

keys = [6,9,10]queries = [[2,3],[9,10]]return = [8,2]

For divisors 2 and 3, two keys are divisible by each divisor, so each contributes 2^2 = 4. Divisors 9 and 10 each divide one key and contribute one vector.

Example 2

keys = [1,2,4]queries = [[1,4]]return = [14]

The counts of divisible keys for divisors 1 through 4 are 3, 2, 0, and 1, giving 9 + 4 + 0 + 1 = 14.

Constraints

  • 1 <= keys.length <= 100000
  • 1 <= keys[i] <= 100000
  • 1 <= queries.length <= 100000
  • Each query has two values with 1 <= left <= right <= 100000.
  • Each answer fits in a signed 64-bit integer.

More Visa Online Assessment questions

  • Count Prime Values in SubtreesOA · Seen Nov 2026
  • Lock CodeOA · Seen Nov 2026
  • Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
  • Longest Non-Decreasing Substring After Pair SwapsOA · Seen Oct 2026
  • Minimum Operations to Reduce a Transaction LedgerOA · Seen Oct 2026
  • Count Valid Space-Delimited WordsOA · Seen Oct 2026
  • Earliest Common Meeting StartOA · Seen Oct 2026
  • Maximum Index-Weighted Sum with Disjoint SwapsOA · Seen Oct 2026
  • Maximum Equalized Substrings After One Adjacent SwapOA · Seen Sep 2026
  • Minimum Values with Even Powers of TwoOA · Seen Sep 2026

Similar questions at other companies

  • Count Subarrays with a Perfect-Square ProductMicrosoft · OA
  • Count Analogous ArraysAtlassian · OA
  • Prefix Scores With the Running MaximumC3.ai · OA
  • Online No-Intercept Linear RegressionTwo Sigma · OA
  • Array Challenge (QR Intern)Akuna Capital · OA
  • Random Pick with Weight Using Recorded DrawsGoogle · PHONE SCREEN · ONSITE INTERVIEW
  • Random Pick with Weight Using Recorded DrawsAmazon · ONSITE INTERVIEW
  • Multinomial Sampling with Distribution ChecksNVIDIA · ONSITE INTERVIEW
  • Random Pick with Weight Using Recorded DrawsMeta · PHONE SCREEN
  • Longest Stationary Sensor IntervalWayve · PHONE SCREEN
See Visa hiring insights
Saved
class Solution {
    public long[] countAttackVectors(int[] keys, int[][] queries) {
        // Write your code here.
    }

}
Checking account…