Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given two sorted integer arrays and a target value T, determinewhether or not th

ID: 3611595 • Letter: G

Question

Given two sorted integer arrays and a target value T, determinewhether or not there exists a pair of numbers, one from the firstarray and one from the second array that add up to T.

For example, if the two arrays were:

2

3

8

9

12

22

25

and

1

5

11

23

45

48

52

59

71

and the target value was 57, then the answer would be yesbecause 9 (from the first array) plus 48 (second array) equals57.

// Pre-condition: vals1 is sorted in non-descending order

// and is of length len1, vals2 is sorted

// similarly and is of length len2.

// Post-condition: 1 is returned if there exists a value

// in vals1 when added to some value in

// vals2 equals target. If no pair of

// values exist, 0 is returned.

int arraySum(int vals1[], int len1, int vals2[], int len2,

int target);

2

3

8

9

12

22

25

Explanation / Answer

A quick stab of logic here (this may not be correct syntax, pleasecorrect as necessary)... int arraySum(int vals1[], int len1, int vals2[], int len2, inttarget) {     int diff, remainder, i, j; i = 0;     diff = target - vals1[i];    while (diff > 0 && i = 0&& j
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote