Practice Sorted GCD Pair Queries
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Sorted GCD Pair Queries
Problem Statement
You are given an integer array nums of length n and an integer array queries. Let gcdPairs denote an array obtained by calculating the GCD of all possible pairs (nums[i], nums[j]), where 0 <= i < j < n, and then sorting these values in ascending order. For each query queries[i], you need to find the element at index queries[i] in gcdPairs. Return an integer array answer, where answer[i] is the value at gcdPairs[queries[i]] for each query. The term gcd(a, b) denotes the greatest common divisor of a and b.
Source: Sorted GCD Pair Queries on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
nums = [2,3,4], queries = [0,2,2]
[1,2,2]
# Example 2
nums = [4,4,2,1], queries = [5,3,1,0]
[4,2,1,1]
# Example 3
nums = [2,2], queries = [0,0]
[2,2]
Constraints
Related LeetCode Problems
Practice more problems similar to Sorted GCD Pair Queries.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.