Solutions for contiguous elements of the list

    • @kristeencoupp91
    • @Ethan, submitted in Python 2, achived 100% score
    import json,random
    def solve(arr, target):
        summed = 0
    
        start, end = 0, 0
        i = 0
        while i < len(arr):
            if summed == target:
                return arr[start:end]
            elif summed > target:
                summed -= arr[start]
                start += 1
            else:
                summed += arr[i]
                end = i + 1
                i += 1
    • @kristeencoupp91
    • @Ethan, submitted in Python 2, achived 100% score
    import json,random
    def solve(arr, target):
        summed = 0
    
        start, end = 0, 0
        i = 0
        while i < len(arr):
            if summed == target:
                return arr[start:end]
            elif summed > target:
                summed -= arr[start]
                start += 1
            else:
                summed += arr[i]
                end = i + 1
                i += 1
    • @kristeencoupp91
    • @Ethan, submitted in Python 3, achived 100% score
    import json,random
    def solve(arr, target):
        summed = 0
    
        start, end = 0, 0
        i = 0
        while i < len(arr):
            if summed == target:
                return arr[start:end]
            elif summed > target:
                summed -= arr[start]
                start += 1
            else:
                summed += arr[i]
                end = i + 1
                i += 1