{"id":"43224d7d-7317-4db5-9dc8-b2a79e7e05ec","name":"Largest Subarray With Contiguous Elements","description":"1. You are given an array(arr) of integers. Values may be duplicated.\r\n2. You have to find the length of the largest subarray with contiguous elements.\r\n\r\nNote -> The contiguous elements can be in any order(not necessarily in increasing order).","inputFormat":"A number N\r\narr1\r\narr2.. N numbers","outputFormat":"A number representing the length of the largest subarray with contiguous elements.","constraints":"1 &lt;= N &lt;= 10^4\r\n1 &lt;= arr[i] &lt;= 10^3","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\n\nusing namespace std;\n\nint solution(vector<int> &arr){\n // write your code here\n}\n\nint main() {\n int n;\n cin >> n;\n vector<int> arr(n, 0);\n for(int i = 0; i < n; i++){\n cin >> arr[i];\n }\n cout << solution(arr) << endl;\n}"},"java":{"code":"import 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\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[] arr = new int[scn.nextInt()];\r\n\t\tfor (int i = 0; i < arr.length; 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\n10 12 11","sampleOutput":"3\r\n","questionVideo":"https://www.youtube.com/embed/37MdIo-MaSU?end=56","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":"1b810ee2-aedd-4618-a510-a60bf818aba6","name":"Largest Subarray With Contiguous Elements","slug":"largest-subarray-with-contiguous-elements","type":1}],"next":{"id":"aab0b93a-49c9-43c2-8f5a-4b890a45d122","name":"Largest Subarray With Contiguous Elements MCQ","type":0,"slug":"largest-subarray-with-contiguous-elements-mcq"},"prev":{"id":"67a92232-bed4-4b17-8d11-2f866696c646","name":"Count Of All Subarrays With Zero Sum","type":3,"slug":"count-of-all-subarrays-with-zero-sum"}}}

Largest Subarray With Contiguous Elements

1. You are given an array(arr) of integers. Values may be duplicated. 2. You have to find the length of the largest subarray with contiguous elements. Note -> The contiguous elements can be in any order(not necessarily in increasing order).

{"id":"43224d7d-7317-4db5-9dc8-b2a79e7e05ec","name":"Largest Subarray With Contiguous Elements","description":"1. You are given an array(arr) of integers. Values may be duplicated.\r\n2. You have to find the length of the largest subarray with contiguous elements.\r\n\r\nNote -> The contiguous elements can be in any order(not necessarily in increasing order).","inputFormat":"A number N\r\narr1\r\narr2.. N numbers","outputFormat":"A number representing the length of the largest subarray with contiguous elements.","constraints":"1 &lt;= N &lt;= 10^4\r\n1 &lt;= arr[i] &lt;= 10^3","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\n\nusing namespace std;\n\nint solution(vector<int> &arr){\n // write your code here\n}\n\nint main() {\n int n;\n cin >> n;\n vector<int> arr(n, 0);\n for(int i = 0; i < n; i++){\n cin >> arr[i];\n }\n cout << solution(arr) << endl;\n}"},"java":{"code":"import 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\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[] arr = new int[scn.nextInt()];\r\n\t\tfor (int i = 0; i < arr.length; 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\n10 12 11","sampleOutput":"3\r\n","questionVideo":"https://www.youtube.com/embed/37MdIo-MaSU?end=56","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":"1b810ee2-aedd-4618-a510-a60bf818aba6","name":"Largest Subarray With Contiguous Elements","slug":"largest-subarray-with-contiguous-elements","type":1}],"next":{"id":"aab0b93a-49c9-43c2-8f5a-4b890a45d122","name":"Largest Subarray With Contiguous Elements MCQ","type":0,"slug":"largest-subarray-with-contiguous-elements-mcq"},"prev":{"id":"67a92232-bed4-4b17-8d11-2f866696c646","name":"Count Of All Subarrays With Zero Sum","type":3,"slug":"count-of-all-subarrays-with-zero-sum"}}}
plane

Editor


Loading...

Largest Subarray With Contiguous Elements

easy

1. You are given an array(arr) of integers. Values may be duplicated. 2. You have to find the length of the largest subarray with contiguous elements. Note -> The contiguous elements can be in any order(not necessarily in increasing order).

Constraints

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

Format

Input

A number N arr1 arr2.. N numbers

Output

A number representing the length of the largest subarray with contiguous elements.

Example

Sample Input

3 10 12 11

Sample Output

3

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode