`{"id":"90f42b7c-099a-4ba0-bb8a-56f3590cd9c3","name":"Arithmetic Slices 1","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-array having all its elements in A.P and the length of sub-array 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;= 10^8\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":"medium","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":"5729ab90-a03e-4fe8-aed3-64bc32af803d","name":"Arithmetic Slices 1","slug":"arithmetic-slices-1","type":1}],"next":{"id":"b19d90df-115a-4462-8e9c-102151f9b471","name":"Arithmetic Slices 2","type":1,"slug":"arithmetic-slices-2"},"prev":{"id":"ccf5215d-6cda-427c-99b5-679e512f1d5a","name":"LCS of Three Strings","type":3,"slug":"lcs-of-three-strings"}}}`

# Arithmetic Slices 1

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-array having all its elements in A.P and the length of sub-array should be greater than or equal to 3.

`{"id":"90f42b7c-099a-4ba0-bb8a-56f3590cd9c3","name":"Arithmetic Slices 1","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-array having all its elements in A.P and the length of sub-array 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;= 10^8\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":"medium","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":"5729ab90-a03e-4fe8-aed3-64bc32af803d","name":"Arithmetic Slices 1","slug":"arithmetic-slices-1","type":1}],"next":{"id":"b19d90df-115a-4462-8e9c-102151f9b471","name":"Arithmetic Slices 2","type":1,"slug":"arithmetic-slices-2"},"prev":{"id":"ccf5215d-6cda-427c-99b5-679e512f1d5a","name":"LCS of Three Strings","type":3,"slug":"lcs-of-three-strings"}}}` Editor

# Arithmetic Slices 1

medium

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-array having all its elements in A.P and the length of sub-array should be greater than or equal to 3.

## Constraints

1 <= N <= 10^8 -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 