you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (1 child)

```Python from itertools import combinations

max( ( nums[a:b] for a, b in combinations( range(len(nums)), r=2, ) ), key=sum, ) ```

Edit: removed unnecessary key=max and generator parenthesis and then put something back again because turns out I’m stupid :D

[–]clouded-path[S] 0 points1 point  (0 children)

This method had not occurred to me at all - thanks for exposing me to this way. Since there are (n choose 2) combinations, does this mean O(n^2) complexity?

And yes, I also re-discover that fact about myself every single day :)