#2761
Prime Pairs With Target Sum
expert · 1050 · lc medium +32 · verified · 37.1% accepted · 407 likes · top 15%
Description
Given an integer n, find all pairs of primes [x, y] with 1 <= x <= y <= n and x + y == n. Return the pairs sorted by x in ascending order, or an empty array if none exist.
Example 1:
Input: n = 10
Output: [[3,7],[5,5]]
Explanation: In this example, there are two prime pairs that satisfy the criteria.
These pairs are [3,7] and [5,5], and we return them in the sorted order as described in the problem statement.
Example 2:
Input: n = 2
Output: []
Explanation: We can show that there is no prime number pair that gives a sum of 2, so we return an empty array.
Code
1
2
3