...

/

Challenge: Closest Target Sum in Two Sorted Arrays

Challenge: Closest Target Sum in Two Sorted Arrays

Test your knowledge of arrays and pointers by solving a coding challenge.

Introduction

We now propose a very similar problem to the previous one. You’ll have to find a naive algorithm and implement it in both pointer and array notation. Then, you’ll have to use the two-pointers technique to implement an optimized solution.

As this is a coding challenge, you must solve it before checking the solution.

Problem statement

Given two arrays sorted in increasing order and a target number, find the pair of elements with the sum closest to the target. One is from the first array, and the other one is from the second array. As opposed to the previous problem, now the pair must contain the elements, not their indices.

In other words, find the pair (e1e_{1}, e2e_{2}), where e1e_{1} is from arr1 and e2e_{2} is from arr2 with the property that |e1e_{1} ...