{"id":"03722bc7-d22b-4138-ac44-03ef76b26d6f","name":"Check Arithmetic Sequence","description":"1. You are given an array(arr) of integers.\r\n2. You have to find if the elements of the given array can be arranged to form an arithmetic progression.\r\n3. Arithmetic progression is defined as a sequence of numbers where the difference between any two consecutive numbers is the same. \r\n\r\nNote -> Try to solve this in linear time complexity.","inputFormat":"A number N\r\narr1\r\narr2.. N numbers","outputFormat":"true/false","constraints":"1 &lt;= N &lt;= 10^6\r\n1 &lt;= arr[i] &lt;= 10^3","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\nbool solution(vector<int> arr) {\n // write your code here\n \n}\n\nint main() {\n\tint n;\n\tcin>>n;\n\tvector<int> arr(n);\n\tfor(int i = 0 ; i < n; i++){\n\t\tint val;\n\t\tcin>>val;\n\t\tarr[i] = val;\n\t}\n\tif(solution(arr))\n\t cout<<\"true\";\n\telse\n\t cout<<\"false\";\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static boolean solution(int[] arr) {\r\n // write your code here\r\n \r\n return 0;\r\n }\r\n \r\n public 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}\r\n"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"3\r\n3 5 1","sampleOutput":"true\r\n","questionVideo":"https://www.youtube.com/embed/_cCSWDQg9qc?end=181","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":"ec6515dc-6811-4c65-912f-0134b65df120","name":"HashMap and Heap For Intermediate","slug":"hashmap-and-heap-for-intermediate-10002","type":0},{"id":"eb19d488-9708-40c6-b711-b68c104e04bd","name":"Check Arithmetic Sequence","slug":"check-arithmetic-sequence","type":1}],"next":{"id":"6561960f-3c3a-4f1e-9d31-eb78e5d85931","name":"Check Arithmetic Sequence MCQ","type":0,"slug":"check-arithmetic-sequence-mcq"},"prev":{"id":"f9a398f5-6874-4b25-add2-e64cb8265066","name":"Double Pair Array","type":3,"slug":"double-pair-array"}}}

Check Arithmetic Sequence

1. You are given an array(arr) of integers. 2. You have to find if the elements of the given array can be arranged to form an arithmetic progression. 3. Arithmetic progression is defined as a sequence of numbers where the difference between any two consecutive numbers is the same. Note -> Try to solve this in linear time complexity.

{"id":"03722bc7-d22b-4138-ac44-03ef76b26d6f","name":"Check Arithmetic Sequence","description":"1. You are given an array(arr) of integers.\r\n2. You have to find if the elements of the given array can be arranged to form an arithmetic progression.\r\n3. Arithmetic progression is defined as a sequence of numbers where the difference between any two consecutive numbers is the same. \r\n\r\nNote -> Try to solve this in linear time complexity.","inputFormat":"A number N\r\narr1\r\narr2.. N numbers","outputFormat":"true/false","constraints":"1 &lt;= N &lt;= 10^6\r\n1 &lt;= arr[i] &lt;= 10^3","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\nbool solution(vector<int> arr) {\n // write your code here\n \n}\n\nint main() {\n\tint n;\n\tcin>>n;\n\tvector<int> arr(n);\n\tfor(int i = 0 ; i < n; i++){\n\t\tint val;\n\t\tcin>>val;\n\t\tarr[i] = val;\n\t}\n\tif(solution(arr))\n\t cout<<\"true\";\n\telse\n\t cout<<\"false\";\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static boolean solution(int[] arr) {\r\n // write your code here\r\n \r\n return 0;\r\n }\r\n \r\n public 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}\r\n"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"3\r\n3 5 1","sampleOutput":"true\r\n","questionVideo":"https://www.youtube.com/embed/_cCSWDQg9qc?end=181","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":"ec6515dc-6811-4c65-912f-0134b65df120","name":"HashMap and Heap For Intermediate","slug":"hashmap-and-heap-for-intermediate-10002","type":0},{"id":"eb19d488-9708-40c6-b711-b68c104e04bd","name":"Check Arithmetic Sequence","slug":"check-arithmetic-sequence","type":1}],"next":{"id":"6561960f-3c3a-4f1e-9d31-eb78e5d85931","name":"Check Arithmetic Sequence MCQ","type":0,"slug":"check-arithmetic-sequence-mcq"},"prev":{"id":"f9a398f5-6874-4b25-add2-e64cb8265066","name":"Double Pair Array","type":3,"slug":"double-pair-array"}}}
plane

Editor


Loading...

Check Arithmetic Sequence

easy

1. You are given an array(arr) of integers. 2. You have to find if the elements of the given array can be arranged to form an arithmetic progression. 3. Arithmetic progression is defined as a sequence of numbers where the difference between any two consecutive numbers is the same. Note -> Try to solve this in linear time complexity.

Constraints

1 <= N <= 10^6 1 <= arr[i] <= 10^3

Format

Input

A number N arr1 arr2.. N numbers

Output

true/false

Example

Sample Input

3 3 5 1

Sample Output

true

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode