Finding values of A and B from an array so that addition or subtraction equals to 40 -


recently in interview asked question.

given:

  1. a + or - b = 40 // can choose 1 operator + or -

  2. [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 ?


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -