Menu
Coddy logo textTech

K-Pair (follow-up)

Lesson 2 of 3 in Coddy's Interview Coding Challenges - Pack IV course.

The same question from before, but now with time complexity constraint - you must solve it in O(n).

challenge icon

Challenge

Medium

Write a function findPair which gets an array of integers arr and a target number k and returns true if there are a pair of integers in arr that sums up to k, otherwise returns false.

 

Example,

Input - arr = [1, 2, 3, 4], k = 6 

Expected output - true

Explanation - The pair (2, 4) which exists in arr sums to k (It's the only pair also!)

 

Note: arr is not sorted array.

Try it yourself

#include <stdbool.h>

bool findPair(int* arr, int arrSize, int k) {
    // Write code here
}

All lessons in Interview Coding Challenges - Pack IV

1Challenges

K-Pair (warm-up)K-Pair (follow-up)K,L Domino