Your Dashboard
Interview Coaching
Learn
System Design
ML System Design
Code
Behavioral
Salary Negotiation
Interview Guides
Search
⌘K
Get Premium
Leetcode 3312. Sorted GCD Pair Queries
Given nums up to 1e5 elements with values ≤ 5e4, compute how many pairs have each possible gcd value by counting numbers divisible by d and using inclusion–exclusion over multiples (sieve-like subtraction) to get exact pair counts for each gcd, then build cumulative counts and binary-search/map queries to the sorted gcd-pairs array. This avoids enumerating all O(n^2) pairs by leveraging divisor counting and prefix sums.
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
All Regions
Comments
Hello Interview Premium
Your account is free and you can post anonymously if you choose.