`{"id":"0a699eb1-8447-4d85-a610-71a776f51d98","name":"Arithmetic Slices 2","description":"1. You are given an array(arr) of integers.\r\n2. You have to find the count of arithmetic slices in the given array.\r\n3. Arithmetic slice is defined as the sub-sequence of an array having all its elements in A.P and length of sub-sequence should be greater than or equal to 3.","inputFormat":"A number N\r\narr1\r\narr2.. N numbers","outputFormat":"Check the sample output and question video.","constraints":"1 &lt;= N &lt;= 1000\r\n-10^8 &lt;= arr[i] &lt;= 10^8","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static int solution(int[] arr) {\r\n\t\t//write your code here\r\n\t\t\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\t\tint[] arr = new int[n];\r\n\t\tfor(int i = 0 ; i < n; i++){\r\n\t\t\tarr[i] = scn.nextInt();\r\n\t\t}\r\n\t\tSystem.out.println(solution(arr));\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"hard","sampleInput":"4\r\n1\r\n2\r\n3\r\n4","sampleOutput":"3\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"b19d90df-115a-4462-8e9c-102151f9b471","name":"Arithmetic Slices 2","slug":"arithmetic-slices-2","type":1}],"next":{"id":"39b6079d-b13c-41ed-91d5-598e591c555e","name":"Word Break 2","type":1,"slug":"word-break-2"},"prev":{"id":"5729ab90-a03e-4fe8-aed3-64bc32af803d","name":"Arithmetic Slices 1","type":1,"slug":"arithmetic-slices-1"}}}`

# Arithmetic Slices 2

1. You are given an array(arr) of integers. 2. You have to find the count of arithmetic slices in the given array. 3. Arithmetic slice is defined as the sub-sequence of an array having all its elements in A.P and length of sub-sequence should be greater than or equal to 3.

`{"id":"0a699eb1-8447-4d85-a610-71a776f51d98","name":"Arithmetic Slices 2","description":"1. You are given an array(arr) of integers.\r\n2. You have to find the count of arithmetic slices in the given array.\r\n3. Arithmetic slice is defined as the sub-sequence of an array having all its elements in A.P and length of sub-sequence should be greater than or equal to 3.","inputFormat":"A number N\r\narr1\r\narr2.. N numbers","outputFormat":"Check the sample output and question video.","constraints":"1 &lt;= N &lt;= 1000\r\n-10^8 &lt;= arr[i] &lt;= 10^8","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static int solution(int[] arr) {\r\n\t\t//write your code here\r\n\t\t\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\t\tint[] arr = new int[n];\r\n\t\tfor(int i = 0 ; i < n; i++){\r\n\t\t\tarr[i] = scn.nextInt();\r\n\t\t}\r\n\t\tSystem.out.println(solution(arr));\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"hard","sampleInput":"4\r\n1\r\n2\r\n3\r\n4","sampleOutput":"3\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"b19d90df-115a-4462-8e9c-102151f9b471","name":"Arithmetic Slices 2","slug":"arithmetic-slices-2","type":1}],"next":{"id":"39b6079d-b13c-41ed-91d5-598e591c555e","name":"Word Break 2","type":1,"slug":"word-break-2"},"prev":{"id":"5729ab90-a03e-4fe8-aed3-64bc32af803d","name":"Arithmetic Slices 1","type":1,"slug":"arithmetic-slices-1"}}}` Editor

# Arithmetic Slices 2

hard

1. You are given an array(arr) of integers. 2. You have to find the count of arithmetic slices in the given array. 3. Arithmetic slice is defined as the sub-sequence of an array having all its elements in A.P and length of sub-sequence should be greater than or equal to 3.

## Constraints

1 <= N <= 1000 -10^8 <= arr[i] <= 10^8

## Format

### Input

A number N arr1 arr2.. N numbers

### Output

Check the sample output and question video.

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}4 1 2 3 4```

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}3 ```

Discussions

Show Discussion

Related Resources 