Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Write a function to find all pairs in an array whose sum is equal to a given target.

Medium

Problem Statement

Write a function to find all pairs in an array whose sum is equal to a given target.

Sample Input

Array: [1, 2, 3, 4, 5], Target: 5

Sample Output

Pairs: [(2, 3), (1, 4)]

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
fun findPairsWithSum(arr: Array<Int>, target: Int): List<Pair<Int, Int>> { // Add your code here to find pairs with the given sum } fun main() { val array = arrayOf(1, 2, 3, 4, 5) val target = 5 println("Pairs: ${findPairsWithSum(array, target)}") }
Log in or sign up to run or submit your code.Log inSign up
Input
Array: [1, 2, 3, 4, 5], Target: 5
Expected Output
Pairs: [(2, 3), (1, 4)]