{"id":"ed3d6029-1a6a-4cbc-a80d-36a9e7e417b0","name":"Span Of Array","description":"1. You are given a number n, representing the count of elements.\r\n2. You are given n numbers.\r\n3. You are required to find the span of input. Span is defined as difference of maximum value and minimum value.","inputFormat":"A number n\r\nn1\r\nn2\r\n.. n number of elements","outputFormat":"A number representing max - min","constraints":"1 &lt;= n &lt;= 10^4\r\n0 &lt;= n1, n2\r\n .. n elements &lt;= 10 ^9","sampleCode":{"cpp":{"code":"#include<iostream>\r\nusing namespace std;\r\n\r\nint main(){\r\n //write your code here\r\n \r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main{\r\n\r\npublic static void main(String[] args) throws Exception {\r\n // write your code here\r\n }\r\n\r\n}"},"python":{"code":"def getSpan(arr):\n # write your code here\n\n\nif __name__ == '__main__':\n num = int(input())\n \n arr=[0]*num\n for i in range(0,num):\n val=int(input())\n arr[i]=val\n \n solution = getSpan(arr)\n print(solution)"}},"points":10,"difficulty":"easy","sampleInput":"6\r\n15\r\n30\r\n40\r\n4\r\n11\r\n9","sampleOutput":"36","questionVideo":"https://www.youtube.com/embed/8erugyv3WDA","hints":[],"associated":[{"id":"300056ca-625b-42a7-affa-9c37c5510e91","name":"(Span of array) Can you solve this problem using Recursion?","slug":"span-of-array-can-you-solve-this-problem-using-recursion","type":4},{"id":"53772db3-b7a8-4ca8-9439-d1740cbd4032","name":"(Span of array) hat will be the output for an array of size 0 ?","slug":"span-of-array-hat-will-be-the-output-for-an-array-of-size-0","type":4},{"id":"8af12454-0607-426a-bd24-4bc5d52fd6c9","name":"(Span of array) What will be the output of given input ?","slug":"span-of-array-what-will-be-the-output-of-given-input","type":4}],"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":"f10b54f1-0f44-408f-82d5-89c189f4ad57","name":"Function and Arrays","slug":"function-and-arrays","type":0},{"id":"9e59f91b-4cb4-42c8-b0bb-c139f18beda2","name":"Span Of Array","slug":"span-of-array","type":1}],"next":{"id":"1866f952-37f1-4aaf-a3e2-1638fdd7fc9b","name":"Span of an Array","type":3,"slug":"span-of-an-array"},"prev":{"id":"bcc8b064-91b8-41cd-a0f4-5c084c7b4fd4","name":"Arrays - Memory Management Theory","type":0,"slug":"arrays-memory-management-theory"}}}

Span Of Array

1. You are given a number n, representing the count of elements. 2. You are given n numbers. 3. You are required to find the span of input. Span is defined as difference of maximum value and minimum value.

{"id":"ed3d6029-1a6a-4cbc-a80d-36a9e7e417b0","name":"Span Of Array","description":"1. You are given a number n, representing the count of elements.\r\n2. You are given n numbers.\r\n3. You are required to find the span of input. Span is defined as difference of maximum value and minimum value.","inputFormat":"A number n\r\nn1\r\nn2\r\n.. n number of elements","outputFormat":"A number representing max - min","constraints":"1 &lt;= n &lt;= 10^4\r\n0 &lt;= n1, n2\r\n .. n elements &lt;= 10 ^9","sampleCode":{"cpp":{"code":"#include<iostream>\r\nusing namespace std;\r\n\r\nint main(){\r\n //write your code here\r\n \r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main{\r\n\r\npublic static void main(String[] args) throws Exception {\r\n // write your code here\r\n }\r\n\r\n}"},"python":{"code":"def getSpan(arr):\n # write your code here\n\n\nif __name__ == '__main__':\n num = int(input())\n \n arr=[0]*num\n for i in range(0,num):\n val=int(input())\n arr[i]=val\n \n solution = getSpan(arr)\n print(solution)"}},"points":10,"difficulty":"easy","sampleInput":"6\r\n15\r\n30\r\n40\r\n4\r\n11\r\n9","sampleOutput":"36","questionVideo":"https://www.youtube.com/embed/8erugyv3WDA","hints":[],"associated":[{"id":"300056ca-625b-42a7-affa-9c37c5510e91","name":"(Span of array) Can you solve this problem using Recursion?","slug":"span-of-array-can-you-solve-this-problem-using-recursion","type":4},{"id":"53772db3-b7a8-4ca8-9439-d1740cbd4032","name":"(Span of array) hat will be the output for an array of size 0 ?","slug":"span-of-array-hat-will-be-the-output-for-an-array-of-size-0","type":4},{"id":"8af12454-0607-426a-bd24-4bc5d52fd6c9","name":"(Span of array) What will be the output of given input ?","slug":"span-of-array-what-will-be-the-output-of-given-input","type":4}],"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":"f10b54f1-0f44-408f-82d5-89c189f4ad57","name":"Function and Arrays","slug":"function-and-arrays","type":0},{"id":"9e59f91b-4cb4-42c8-b0bb-c139f18beda2","name":"Span Of Array","slug":"span-of-array","type":1}],"next":{"id":"1866f952-37f1-4aaf-a3e2-1638fdd7fc9b","name":"Span of an Array","type":3,"slug":"span-of-an-array"},"prev":{"id":"bcc8b064-91b8-41cd-a0f4-5c084c7b4fd4","name":"Arrays - Memory Management Theory","type":0,"slug":"arrays-memory-management-theory"}}}
plane

Editor


Loading...

Span Of Array

easy

1. You are given a number n, representing the count of elements. 2. You are given n numbers. 3. You are required to find the span of input. Span is defined as difference of maximum value and minimum value.

Constraints

1 <= n <= 10^4 0 <= n1, n2 .. n elements <= 10 ^9

Format

Input

A number n n1 n2 .. n number of elements

Output

A number representing max - min

Example

Sample Input

6 15 30 40 4 11 9

Sample Output

36

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode