medium Arrays 100 points

Find All Pairs of Elements in Array

Write a function to find all pairs of elements in an array such that their sum equals a target value. The function should return all pairs in a 2D array, where each pair is sorted in ascending order. If no such pair exists, return an empty array. For example, if the input array is [1, 2, 3, 4, 5] and the target value is 7, the function should return [[2, 5], [3, 4]] because 2 + 5 = 7 and 3 + 4 = 7.

Problem Description

Write a function to find all pairs of elements in an array such that their sum equals a target value. The function should return all pairs in a 2D array, where each pair is sorted in ascending order. If no such pair exists, return an empty array. For example, if the input array is [1, 2, 3, 4, 5] and the target value is 7, the function should return [[2, 5], [3, 4]] because 2 + 5 = 7 and 3 + 4 = 7.

Examples

Example

Input: [1, 2, 3, 4, 5]

Output: [[2, 5], [3, 4]]

Challenge Info

100 Points

Reward

medium

Difficulty

No limit

Time Limit

Submission Stats

Total Submissions 0
Accepted 0
Success Rate 0%