def smallest_subarray_with_given_sum(arr, s):
    """Find the length of the smallest subarray whose sum is >= s.

    Time:  O(n)
    Space: O(1)

    >>> smallest_subarray_with_given_sum([2, 1, 5, 2, 3, 2], 7)
    2

    >>> smallest_subarray_with_given_sum([2, 1, 5, 2, 8], 7)
    1

    >>> smallest_subarray_with_given_sum([3, 4, 1, 1, 6], 8)
    3

    """
    win_sum = 0
    win_start = 0
    min_len = 0
    for win_end in range(len(arr)):
        win_sum += arr[win_end]
        while win_sum >= s:
            cur_len = win_end - win_start + 1
            if min_len == 0 or cur_len < min_len:
                min_len = cur_len
            win_sum -= arr[win_start]
            win_start += 1
    return min_len