---
# System prepended metadata

title: Array Sums

---

# Array Sums 

## The problem statement is 

Given two arrays, array1, array2 and a target number, re-arrange the second array such that the sum of the corresponding indices of the arrays adds up to the target.

## Example

array1: `[3, 4, 5]`
array2: `[4, 6, 5]`
target: `9`

your goal is to rearrange array2 in such a way that the numbers at corresponding inces add up to the target

PLEASE NOTE: You do not need to account for the edge case where the target is never reached :) 

#### expected return 
`[6, 5, 4]`

## Example 1 Explanation 

when the second array is reordered to be `[6, 5, 4]` the corresponding indeces add up to 9 which is our target in this case

`[3, 4, 5]`
`[6, 5, 4]`

now `[3,6]`, `[4, 5]` and `[5, 4]` are index pairs and they add up to 9 in each case

## Test Cases

### Test Case 1
array1: `[3, 6, 4, 2]`
array2: `[4, 3, 2, 0]`
target: `6`

expected output: `[3, 0, 2, 4]`

### Test Case 2
array1: `[4, 6, 2, 5, 4]`
array2: `[2, 4, 3, 4, 6]`
target: `8`

expected output: `[4, 2, 6, 3, 4]`


