• Source
    1. def smallest_sub_sum_greater_than_n(data, n):
    2. current = []
    3. smaller = []
    4. i = 0
    5. j = 0
    6. while i < len(data):
    7. current = data[i:j]
    8. current_sum = sum(value for value in current);
    9. if current_sum > n:
    10. if ( len(current) < len(smaller) ) or len(smaller) == 0:
    11. smaller = current
    12. else:
    13. i = i + 1
    14. else:
    15. j = j + 1
    16. if j > len(data):
    17. i = i + 1
    18. j = i
    19. return len(smaller), smaller
    20.  
    21. print smallest_sub_sum_greater_than_n([1, 4, 45, 6, 0, 1], 51)
    22. print smallest_sub_sum_greater_than_n([1, 10, 5, 2 ], 9)
    23. print smallest_sub_sum_greater_than_n([1, 11, 100, 1, 0, 200, 3, 2, 1, 250], 280)
    24.  
    25.  
    26.  
    27.  
    28.