Question: An array is defined to be paired - N if it contains two distinct elements that sum to N for some specified value of N
An array is defined to be pairedN if it contains two distinct elements that sum to N for some specified value of N and the indexes of those elements also sum to N Write a function named isPairedN that returns if its array parameter is a pairedN array. The value of N is passed as the second parameter.
If you are writing in Java, the function signature is
int isPairedNint a int n
There are two additional requirements.
Once you know the array is pairedN you should return No wasted loop iterations please.
Do not enter the loop unless you have to You should test the length of the array and the value of n to determine whether the array could possibly be a pairedN array. If the tests indicate no return before entering the loop. NB: youshould use java programming language
Examples
if a is and n is return reason
because a a and In other words, the sum of the values is equal to the sum of the corresponding indexes and both are equal to n in this case
because a a and
because aa and
because although a a; and although aa
because there are several ways to get the values to sum to but there is no way to get the corresponding indexes to sum to
because although aa
because the array has only one element
because the array has no elements
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
