Arithmetic Slices

Company: Rakuten

Difficulty: medium

Problem Statement

Arithmetic Slices Problem Description A sensor records a sequence of n integer readings nums[0], nums[1], ..., nums[n - 1] . A steady stretch is a block of consecutive readings nums[l], nums[l + 1], ..., nums[r] that contains at least three readings ( r - l + 1 >= 3 ), and changes by the same amount at every step: nums[i + 1] - nums[i] has one common value for every i with l <= i < r . The common step may be positive, negative or zero. Two stretches are different if they start or end at different positions, so a long steady block also contains all of its shorter steady blocks of length 3 or more. Complete the function numberOfArithmeticSlices(nums) , which returns the number of steady stretches in nums . Input Format Read from standard input. n nums[0] nums[1] ... nums[n-1] The first line contains an integer n , the number of readings. The second line contains n space-separated integers, the readings in order. Output Format Print a single integer: the number of steady stretche