{"id":"450fdb75-b174-4689-9742-391c2b5cbfd4","name":"Max Of An 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 maximum of input. \r\n4. For the purpose complete the body of maxOfArray function. Don't change the signature.\r\n\r\nNote -> The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.","inputFormat":"A number n\r\nn1\r\nn2\r\n.. n number of elements","outputFormat":"A number representing max","constraints":"1 &lt;= n &lt;= 10^4\r\n0 &lt;= n1, n2, .. n elements &lt;= 10 ^9","sampleCode":{"cpp":{"code":"#include <iostream>\r\nusing namespace std;\r\n\r\nint max(int arr[], int idx, int n){\r\n // write your code here\r\n \r\n}\r\n\r\nint main(){\r\n int n;\r\n cin >> n;\r\n int arr[n];\r\n for (int i = 0; i < n; i++)\r\n cin >> arr[i];\r\n int p = max(arr, 0, n);\r\n cout << p << endl;\r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n // write your code here\r\n }\r\n\r\n public static int maxOfArray(int[] arr, int idx){\r\n return 0;\r\n }\r\n\r\n}"},"python":{"code":"import sys\nsys.setrecursionlimit (10000)\n\ndef max(arr,idx,n):\n # Write your code here\n\n\ndef main():\n n=int(input())\n arr=[]\n for i in range(n):\n arr.append(int(input()))\n res=max(arr,0,n)\n print(res)\nmain()"}},"points":10,"difficulty":"easy","sampleInput":"6\r\n15\r\n30\r\n40\r\n4\r\n11\r\n9","sampleOutput":"40","questionVideo":"https://www.youtube.com/embed/obrreX-sQWo","hints":[],"associated":[{"id":"87eb2e88-8693-4e46-9108-dae40f516dc7","name":"(Max of Array) What should be your condition for the termination of the program while travelling from left to right?","slug":"max-of-array-what-should-be-your-condition-for-the-termination-of-the-program-while-travelling-from-left-to-right","type":4},{"id":"b7331167-fa32-465b-83b4-b342762c0146","name":"(Max of Array) Will the code run if the size of an array is is 1 ?","slug":"max-of-array-will-the-code-run-if-the-size-of-an-array-is-is-1","type":4},{"id":"c38d5a2d-f2d0-43e7-9a90-97263319915d","name":"(Max of Array) For the given array what will be your recursive relation ?","slug":"max-of-array-for-the-given-array-what-will-be-your-recursive-relation","type":4},{"id":"f3356eea-6785-4ae3-84d6-fead5a1ce6bf","name":"(Max of Array) Why time complexity of this solution is O(n) ?","slug":"max-of-array-why-time-complexity-of-this-solution-is-o-n","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":"d341a7c9-1269-409c-b851-0bb512289544","name":"Recursion And Backtracking For Beginners","slug":"recursion-and-backtracking-for-beginners","type":0},{"id":"e441eef8-edee-43d8-8963-ea3b7ed409a6","name":"Max Of An Array","slug":"max-of-an-array","type":1}],"next":{"id":"14f4517b-0784-48bb-b607-470917f56da9","name":"Max of an Array","type":3,"slug":"max-of-an-array"},"prev":{"id":"6c14b3f0-23c0-4692-9b00-7fd245e551bf","name":"Display Array Reverse","type":3,"slug":"display-array-reverse"}}}

Max Of An 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 maximum of input. 4. For the purpose complete the body of maxOfArray function. Don't change the signature. Note -> The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.

{"id":"450fdb75-b174-4689-9742-391c2b5cbfd4","name":"Max Of An 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 maximum of input. \r\n4. For the purpose complete the body of maxOfArray function. Don't change the signature.\r\n\r\nNote -> The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.","inputFormat":"A number n\r\nn1\r\nn2\r\n.. n number of elements","outputFormat":"A number representing max","constraints":"1 &lt;= n &lt;= 10^4\r\n0 &lt;= n1, n2, .. n elements &lt;= 10 ^9","sampleCode":{"cpp":{"code":"#include <iostream>\r\nusing namespace std;\r\n\r\nint max(int arr[], int idx, int n){\r\n // write your code here\r\n \r\n}\r\n\r\nint main(){\r\n int n;\r\n cin >> n;\r\n int arr[n];\r\n for (int i = 0; i < n; i++)\r\n cin >> arr[i];\r\n int p = max(arr, 0, n);\r\n cout << p << endl;\r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n // write your code here\r\n }\r\n\r\n public static int maxOfArray(int[] arr, int idx){\r\n return 0;\r\n }\r\n\r\n}"},"python":{"code":"import sys\nsys.setrecursionlimit (10000)\n\ndef max(arr,idx,n):\n # Write your code here\n\n\ndef main():\n n=int(input())\n arr=[]\n for i in range(n):\n arr.append(int(input()))\n res=max(arr,0,n)\n print(res)\nmain()"}},"points":10,"difficulty":"easy","sampleInput":"6\r\n15\r\n30\r\n40\r\n4\r\n11\r\n9","sampleOutput":"40","questionVideo":"https://www.youtube.com/embed/obrreX-sQWo","hints":[],"associated":[{"id":"87eb2e88-8693-4e46-9108-dae40f516dc7","name":"(Max of Array) What should be your condition for the termination of the program while travelling from left to right?","slug":"max-of-array-what-should-be-your-condition-for-the-termination-of-the-program-while-travelling-from-left-to-right","type":4},{"id":"b7331167-fa32-465b-83b4-b342762c0146","name":"(Max of Array) Will the code run if the size of an array is is 1 ?","slug":"max-of-array-will-the-code-run-if-the-size-of-an-array-is-is-1","type":4},{"id":"c38d5a2d-f2d0-43e7-9a90-97263319915d","name":"(Max of Array) For the given array what will be your recursive relation ?","slug":"max-of-array-for-the-given-array-what-will-be-your-recursive-relation","type":4},{"id":"f3356eea-6785-4ae3-84d6-fead5a1ce6bf","name":"(Max of Array) Why time complexity of this solution is O(n) ?","slug":"max-of-array-why-time-complexity-of-this-solution-is-o-n","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":"d341a7c9-1269-409c-b851-0bb512289544","name":"Recursion And Backtracking For Beginners","slug":"recursion-and-backtracking-for-beginners","type":0},{"id":"e441eef8-edee-43d8-8963-ea3b7ed409a6","name":"Max Of An Array","slug":"max-of-an-array","type":1}],"next":{"id":"14f4517b-0784-48bb-b607-470917f56da9","name":"Max of an Array","type":3,"slug":"max-of-an-array"},"prev":{"id":"6c14b3f0-23c0-4692-9b00-7fd245e551bf","name":"Display Array Reverse","type":3,"slug":"display-array-reverse"}}}
plane

Editor


Loading...

Max Of An 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 maximum of input. 4. For the purpose complete the body of maxOfArray function. Don't change the signature. Note -> The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.

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

Example

Sample Input

6 15 30 40 4 11 9

Sample Output

40

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode