Episode 7 — DSA with JavaScript / 7.8 — Advanced Array Problems

7.8.a — Two-Pointer, Prefix Sum & Advanced Techniques

<< 7.8 Overview


Advanced two-pointer problems

Container with most water

Given heights array, find two lines that form a container holding the most water.

height: [1, 8, 6, 2, 5, 4, 8, 3, 7]

  8 |   █           █
  7 |   █           █       █
  6 |   █   █       █       █
  5 |   █   █   █   █       █
  4 |   █   █   █ █ █       █
  3 |   █   █   █ █ █ █     █
  2 |   █   █ █ █ █ █ █     █
  1 | █ █   █ █ █ █ █ █     █
    └─────────────────────────
      0 1 2 3 4 5 6 7 8

Two pointers: L=0, R=8
  Area = min(1,7) × (8-0) = 1 × 8 = 8
  Move shorter side → L=1
  Area = min(8,7) × (8-1) = 7 × 7 = 49 ← max
function maxArea(height) {
    let l = 0, r = height.length - 1, max = 0;
    while (l < r) {
        const area = Math.min(height[l], height[r]) * (r - l);
        max = Math.max(max, area);
        if (height[l] < height[r]) l++;
        else r--;
    }
    return max;
}
int maxArea(vector<int>& height) {
    int l = 0, r = height.size() - 1, mx = 0;
    while (l < r) {
        mx = max(mx, min(height[l], height[r]) * (r - l));
        if (height[l] < height[r]) l++;
        else r--;
    }
    return mx;
}

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


Three Sum (find triplets summing to 0)

function threeSum(nums) {
    nums.sort((a, b) => a - b);
    const result = [];
    for (let i = 0; i < nums.length - 2; i++) {
        if (i > 0 && nums[i] === nums[i-1]) continue;
        let l = i + 1, r = nums.length - 1;
        while (l < r) {
            const sum = nums[i] + nums[l] + nums[r];
            if (sum === 0) {
                result.push([nums[i], nums[l], nums[r]]);
                while (l < r && nums[l] === nums[l+1]) l++;
                while (l < r && nums[r] === nums[r-1]) r--;
                l++; r--;
            } else if (sum < 0) l++;
            else r--;
        }
    }
    return result;
}
vector<vector<int>> threeSum(vector<int>& nums) {
    sort(nums.begin(), nums.end());
    vector<vector<int>> result;
    for (int i = 0; i < (int)nums.size() - 2; i++) {
        if (i > 0 && nums[i] == nums[i-1]) continue;
        int l = i + 1, r = nums.size() - 1;
        while (l < r) {
            int sum = nums[i] + nums[l] + nums[r];
            if (sum == 0) {
                result.push_back({nums[i], nums[l], nums[r]});
                while (l < r && nums[l] == nums[l+1]) l++;
                while (l < r && nums[r] == nums[r-1]) r--;
                l++; r--;
            } else if (sum < 0) l++;
            else r--;
        }
    }
    return result;
}

Time: O(n²) | Space: O(1) excluding output


Prefix sum — subarray sum equals K

function subarraySum(nums, k) {
    const prefixCount = new Map([[0, 1]]);
    let sum = 0, count = 0;
    for (const n of nums) {
        sum += n;
        if (prefixCount.has(sum - k)) count += prefixCount.get(sum - k);
        prefixCount.set(sum, (prefixCount.get(sum) || 0) + 1);
    }
    return count;
}

Time: O(n) | Space: O(n)


Variable-size sliding window

Minimum window substring

function minWindow(s, t) {
    const need = {};
    for (const c of t) need[c] = (need[c] || 0) + 1;
    let have = 0, required = Object.keys(need).length;
    let l = 0, minLen = Infinity, minStart = 0;
    const window = {};
    for (let r = 0; r < s.length; r++) {
        const c = s[r];
        window[c] = (window[c] || 0) + 1;
        if (need[c] && window[c] === need[c]) have++;
        while (have === required) {
            if (r - l + 1 < minLen) { minLen = r - l + 1; minStart = l; }
            const lc = s[l];
            window[lc]--;
            if (need[lc] && window[lc] < need[lc]) have--;
            l++;
        }
    }
    return minLen === Infinity ? "" : s.slice(minStart, minStart + minLen);
}

Scenario bank (advanced arrays)

7.8a-001 — Four Sum (v1)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-002 — Subarray product less than K (v2)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-003 — Longest subarray with at most K distinct (v3)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-004 — Maximum sliding window (deque) (v4)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-005 — Minimum size subarray sum (v5)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-006 — Count subarrays with exactly K odd (v6)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-007 — Find all duplicates in array (v7)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-008 — Next permutation (v8)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-009 — Longest increasing subsequence (v9)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-010 — Maximum product subarray (v10)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-011 — Shortest unsorted continuous subarray (v11)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-012 — Partition labels (v12)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-013 — Task scheduler (v13)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-014 — Merge intervals (v14)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-015 — Insert interval (v15)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-016 — Non-overlapping intervals (v16)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-017 — Meeting rooms II (v17)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-018 — Largest rectangle in histogram (v18)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-019 — Maximal rectangle (v19)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-020 — Candy distribution (v20)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-021 — Four Sum (v21)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-022 — Subarray product less than K (v22)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-023 — Longest subarray with at most K distinct (v23)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-024 — Maximum sliding window (deque) (v24)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-025 — Minimum size subarray sum (v25)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-026 — Count subarrays with exactly K odd (v26)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-027 — Find all duplicates in array (v27)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-028 — Next permutation (v28)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-029 — Longest increasing subsequence (v29)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-030 — Maximum product subarray (v30)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-031 — Shortest unsorted continuous subarray (v31)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-032 — Partition labels (v32)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-033 — Task scheduler (v33)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-034 — Merge intervals (v34)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-035 — Insert interval (v35)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-036 — Non-overlapping intervals (v36)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-037 — Meeting rooms II (v37)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-038 — Largest rectangle in histogram (v38)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-039 — Maximal rectangle (v39)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-040 — Candy distribution (v40)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-041 — Four Sum (v41)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-042 — Subarray product less than K (v42)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-043 — Longest subarray with at most K distinct (v43)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-044 — Maximum sliding window (deque) (v44)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-045 — Minimum size subarray sum (v45)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-046 — Count subarrays with exactly K odd (v46)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-047 — Find all duplicates in array (v47)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-048 — Next permutation (v48)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-049 — Longest increasing subsequence (v49)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-050 — Maximum product subarray (v50)

  • Level: Beginner
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-051 — Shortest unsorted continuous subarray (v51)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-052 — Partition labels (v52)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-053 — Task scheduler (v53)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-054 — Merge intervals (v54)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-055 — Insert interval (v55)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-056 — Non-overlapping intervals (v56)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-057 — Meeting rooms II (v57)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-058 — Largest rectangle in histogram (v58)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-059 — Maximal rectangle (v59)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-060 — Candy distribution (v60)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-061 — Four Sum (v61)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-062 — Subarray product less than K (v62)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-063 — Longest subarray with at most K distinct (v63)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-064 — Maximum sliding window (deque) (v64)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-065 — Minimum size subarray sum (v65)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-066 — Count subarrays with exactly K odd (v66)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-067 — Find all duplicates in array (v67)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-068 — Next permutation (v68)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-069 — Longest increasing subsequence (v69)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-070 — Maximum product subarray (v70)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-071 — Shortest unsorted continuous subarray (v71)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-072 — Partition labels (v72)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-073 — Task scheduler (v73)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-074 — Merge intervals (v74)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-075 — Insert interval (v75)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-076 — Non-overlapping intervals (v76)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-077 — Meeting rooms II (v77)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-078 — Largest rectangle in histogram (v78)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-079 — Maximal rectangle (v79)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-080 — Candy distribution (v80)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-081 — Four Sum (v81)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-082 — Subarray product less than K (v82)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-083 — Longest subarray with at most K distinct (v83)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-084 — Maximum sliding window (deque) (v84)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-085 — Minimum size subarray sum (v85)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-086 — Count subarrays with exactly K odd (v86)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-087 — Find all duplicates in array (v87)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-088 — Next permutation (v88)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-089 — Longest increasing subsequence (v89)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-090 — Maximum product subarray (v90)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-091 — Shortest unsorted continuous subarray (v91)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-092 — Partition labels (v92)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-093 — Task scheduler (v93)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-094 — Merge intervals (v94)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-095 — Insert interval (v95)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-096 — Non-overlapping intervals (v96)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-097 — Meeting rooms II (v97)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-098 — Largest rectangle in histogram (v98)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-099 — Maximal rectangle (v99)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-100 — Candy distribution (v100)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-101 — Four Sum (v101)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-102 — Subarray product less than K (v102)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-103 — Longest subarray with at most K distinct (v103)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-104 — Maximum sliding window (deque) (v104)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-105 — Minimum size subarray sum (v105)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-106 — Count subarrays with exactly K odd (v106)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-107 — Find all duplicates in array (v107)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-108 — Next permutation (v108)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-109 — Longest increasing subsequence (v109)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-110 — Maximum product subarray (v110)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-111 — Shortest unsorted continuous subarray (v111)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-112 — Partition labels (v112)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-113 — Task scheduler (v113)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-114 — Merge intervals (v114)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-115 — Insert interval (v115)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-116 — Non-overlapping intervals (v116)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-117 — Meeting rooms II (v117)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-118 — Largest rectangle in histogram (v118)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-119 — Maximal rectangle (v119)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-120 — Candy distribution (v120)

  • Level: Intermediate
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-121 — Four Sum (v121)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-122 — Subarray product less than K (v122)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-123 — Longest subarray with at most K distinct (v123)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-124 — Maximum sliding window (deque) (v124)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-125 — Minimum size subarray sum (v125)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-126 — Count subarrays with exactly K odd (v126)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-127 — Find all duplicates in array (v127)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-128 — Next permutation (v128)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-129 — Longest increasing subsequence (v129)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-130 — Maximum product subarray (v130)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-131 — Shortest unsorted continuous subarray (v131)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-132 — Partition labels (v132)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-133 — Task scheduler (v133)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-134 — Merge intervals (v134)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-135 — Insert interval (v135)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-136 — Non-overlapping intervals (v136)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-137 — Meeting rooms II (v137)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-138 — Largest rectangle in histogram (v138)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-139 — Maximal rectangle (v139)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-140 — Candy distribution (v140)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-141 — Four Sum (v141)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-142 — Subarray product less than K (v142)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-143 — Longest subarray with at most K distinct (v143)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-144 — Maximum sliding window (deque) (v144)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-145 — Minimum size subarray sum (v145)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-146 — Count subarrays with exactly K odd (v146)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-147 — Find all duplicates in array (v147)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-148 — Next permutation (v148)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-149 — Longest increasing subsequence (v149)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-150 — Maximum product subarray (v150)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-151 — Shortest unsorted continuous subarray (v151)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-152 — Partition labels (v152)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-153 — Task scheduler (v153)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-154 — Merge intervals (v154)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-155 — Insert interval (v155)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-156 — Non-overlapping intervals (v156)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-157 — Meeting rooms II (v157)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-158 — Largest rectangle in histogram (v158)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-159 — Maximal rectangle (v159)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-160 — Candy distribution (v160)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-161 — Four Sum (v161)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-162 — Subarray product less than K (v162)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-163 — Longest subarray with at most K distinct (v163)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-164 — Maximum sliding window (deque) (v164)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-165 — Minimum size subarray sum (v165)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-166 — Count subarrays with exactly K odd (v166)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-167 — Find all duplicates in array (v167)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-168 — Next permutation (v168)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-169 — Longest increasing subsequence (v169)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.8a-170 — Maximum product subarray (v170)

  • Level: Advanced
  • Approach: Apply appropriate technique.
  • Time: Analyze.
  • Space: Identify.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.