vendredi 18 janvier 2019

Maximum possible value, as the sum of no more than two elements from the list

On what values of a, b, c will the function produce wrong output?

Constraints:

1> can't take the same element twice in list, but can could take two distinct elements which are equal by value.

2> The length of the list is not greater than 100.

3> Each element of list are positive and not greater than 1000.

list = [a, b, c] 


def solve(list):
  max = 0
  for i in range(len(list)):
    for j in range(len(list)):
      if i != j and list[i] + list[j] > max:
        max = list[i] + list[j]
  return max

Aucun commentaire:

Enregistrer un commentaire