Skip to content

Revision Series

Sliding Window

Important stuff

int helper(vector<int>& nums, int k) {
        int count = 0;
        int left = 0;
        int right = 0;
        int sum = 0;
        int size = nums.size();
        while(right < size) {
            sum += nums[right];
            while(sum > k) {
                sum -= nums[left];
                left++;
            }

            count += (right - left + 1);
            right++;
        }

        return count;
    }
```1
Medium

Longest substring without repeating characters

keep track of the ending index of each character, if detected, shifted left pointer

Fruits into baskets

check if there are two fruits in the window

Count number of nice subarrays

convert to odd numbers, and use the helper function

Number of substring containing all three characters

use mapping to check if all three characters have been detected

Minimum Window Substring

Using map and required variable, try minimizing the window size as much and calculate the size