Skip to content

Practice Arithmetic Slices

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#413
LeetCode Problem

Arithmetic Slices

Problem Statement

An integer array is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same. Given an integer array nums, return the number of arithmetic subarrays of nums. A subarray is a contiguous subsequence of the array.

Source: Arithmetic Slices on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,2,3,4]
Output
3

# Example 2

Input
nums = [1]
Output
0

Constraints

1 <= nums.length <= 5000
-1000 <= nums[i] <= 1000

Related LeetCode Problems

Practice more problems similar to Arithmetic Slices.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.