Finding values of A and B from an array so that addition or subtraction equals to 40 -
recently in interview asked question.
given:
a + or - b = 40 // can choose 1 operator + or -
[list of numbers in array]
explain how choose numbers , b given array make result 40 ?
my answer:
consider 1st element of array a, iterate through array start find possible values of b while process fetch each element array, sum , compare 40.
but not happy.
any other approaches ?