Tap here to switch tabs
Problem
Submissions

Problem: Continuous Subarrays

Continuous Subarrays asks you to count nonempty contiguous portions of an integer array where the difference between any two values is at most two.

Statement

You are given an array of integers nums.

A subarray of nums is called continuous if, for any two elements at indices i and j in the subarray, ∣|nums[i] - nums[j]∣≤2| \leq 2.

Return the total number of continuous subarrays in nums.

Note: A subarray is a contiguous non empty sequence of elements within an array.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Continuous Subarrays

Continuous Subarrays asks you to count nonempty contiguous portions of an integer array where the difference between any two values is at most two.

Statement

You are given an array of integers nums.

A subarray of nums is called continuous if, for any two elements at indices i and j in the subarray, ∣|nums[i] - nums[j]∣≤2| \leq 2.

Return the total number of continuous subarrays in nums.

Note: A subarray is a contiguous non empty sequence of elements within an array.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9