Hacker News new | ask | show | jobs
by nhamann 5232 days ago
Indeed, but it won't even accept the following O(n) solution. I get "(stopped after 20 steps to prevent possible infinite loop)" when submitting this:

  def maxPairSum(lst):
      if lst[0] > lst[1]:
          top, top2 = lst[:2]
      else:
          top2, top = lst[:2]

      for i in range(2, len(lst)):
          if lst[i] > top:
              top, top2 = lst[i], top
          elif lst[i] > top2:
              top2 = lst[i]

      return top+top2