<commit_before>// Time:  O(n)
// Space: O(1)

// Sliding window solution.
class Solution {
public:
    /**
     * @param nums: a vector of integers
     * @param s: an integer
     * @return: an integer representing the minimum size of subarray
     */
    int minimumSize(vector<int> &nums, int s) {
        int start = -1, sum = 0, min_size = INT_MAX;
        for (int i = 0; i < nums.size(); ++i) {
            sum += nums[i];
            while (sum >= s) {
                min_size = min(min_size, i - start);
                sum -= nums[++start];
            }
        }
        if (min_size == INT_MAX) {
            return 0;
        }
        return min_size;
    }
};

// Time:  O(nlogn)
// Space: O(n)
// Binary search solution.
class Solution2 {
public:
    /**
     * @param nums: a vector of integers
     * @param s: an integer
     * @return: an integer representing the minimum size of subarray
     */
    int minimumSize(vector<int> &nums, int s) {
        int min_size = INT_MAX;
        vector<int> sum_from_start(nums.size());
        partial_sum(nums.begin(), nums.end(), sum_from_start.begin());
        for (int i = 0; i < nums.size(); ++i) {
            const auto& end_it = lower_bound(sum_from_start.begin() + i,
                                          sum_from_start.end(),
                                          sum_from_start[i] - nums[i] + s);
            int end = static_cast<int>(end_it - sum_from_start.begin());
            if (end_it != sum_from_start.end()) {
                min_size = min(min_size,  end - i + 1);
            }
        }
        if (min_size == INT_MAX) {
            return 0;
        }
        return min_size;
    }
};<commit_msg>Update minimum-size-subarray-sum.cpp<commit_after>// Time:  O(n)
// Space: O(1)

// Sliding window solution.
class Solution {
public:
    /**
     * @param nums: a vector of integers
     * @param s: an integer
     * @return: an integer representing the minimum size of subarray
     */
    int minimumSize(vector<int> &nums, int s) {
        int start = -1, sum = 0, min_size = INT_MAX;
        for (int i = 0; i < nums.size(); ++i) {
            sum += nums[i];
            while (sum >= s) {
                min_size = min(min_size, i - start);
                sum -= nums[++start];
            }
        }
        if (min_size == INT_MAX) {
            return 0;
        }
        return min_size;
    }
};

// Time:  O(nlogn)
// Space: O(n)
// Binary search solution.
class Solution2 {
public:
    /**
     * @param nums: a vector of integers
     * @param s: an integer
     * @return: an integer representing the minimum size of subarray
     */
    int minimumSize(vector<int> &nums, int s) {
        int min_size = INT_MAX;
        vector<int> sum_from_start(nums.size());
        partial_sum(nums.begin(), nums.end(), sum_from_start.begin());
        for (int i = 0; i < nums.size(); ++i) {
            const auto& end_it = lower_bound(sum_from_start.begin() + i,
                                          sum_from_start.end(),
                                          sum_from_start[i] - nums[i] + s);
            int end = static_cast<int>(end_it - sum_from_start.begin());
            if (end_it != sum_from_start.end()) {
                min_size = min(min_size, end - i + 1);
            }
        }
        if (min_size == INT_MAX) {
            return 0;
        }
        return min_size;
    }
};
{'fraction_non_alphanumeric': 0.1324736225087925, 'fraction_numerical': 0.005275498241500586, 'mean_word_length': 1.583648750946253, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4638335', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1081, 'n_words': 289}