Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Arithmetic Slices

Medium

Topics
ArrayDynamic Programming

An arithmetic slice is a contiguous subarray of length at least 3 with a constant difference between consecutive elements. Return the number of arithmetic slices in nums.

Example 1

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

Example 2

Input:  nums = [1,3,5,7,9]
Output: 6

Example 3

Input:  nums = [1,2,3,8,9,10]
Output: 2

Constraints

  • 1 <= nums.length <= 5000
  • -1000 <= nums[i] <= 1000
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access