`{"id":"2c837aca-7cae-4c0a-8b39-380b38d28eb8","name":"Subarray Problem","description":"1. You are given an array of size 'n' and n elements of the same array.\r\n2. You are required to find and print all the subarrays of the given array. \r\n3. Each subarray should be space seperated and on a seperate lines. Refer to sample input and output.","inputFormat":"A number n\r\nn1\r\nn2\r\n.. n number of elements","outputFormat":"[Tab separated elements of subarray]\r\n..\r\nAll subarrays","constraints":"1 &lt;= n &lt;= 10\r\n0 &lt;= n1, n2\r\n .. n elements &lt;= 10 ^9","sampleCode":{"cpp":{"code":"#include<iostream>\r\nusing namespace std;\r\n\r\n\r\nint main(){\r\n int n;\r\n cin>>n;\r\n int* arr = new int[n];\r\n for(int i = 0 ; i < n; i++){\r\n cin>>arr[i];\r\n }\r\n \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":"n=int(input())\narr=[]\nfor i in range(n):\n val=int(input())\n arr.append(val)\n\n# write your code here"}},"points":10,"difficulty":"easy","sampleInput":"3\r\n10\r\n20\r\n30","sampleOutput":"10\t\r\n10\t20\t\r\n10\t20\t30\t\r\n20\t\r\n20\t30\t\r\n30\t\r\n\r\n","questionVideo":"https://www.youtube.com/embed/YrE8E1J_rp4","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":"f10b54f1-0f44-408f-82d5-89c189f4ad57","name":"Function and Arrays","slug":"function-and-arrays","type":0},{"id":"9035b424-2c38-4f70-8778-6fc638133a3c","name":"Subarray Problem","slug":"subarray-problem","type":1}],"next":{"id":"04d40c08-6f5b-4e5e-9f51-c65f2ffd379b","name":"Sub Arrays Of An Array","type":3,"slug":"sub-arrays-of-an-array"},"prev":{"id":"1cd0ced2-fd4e-44db-85fa-c1ccba0629b3","name":"Inverse Of An Array","type":3,"slug":"inverse-of-an-array"}}}`

# Subarray Problem

1. You are given an array of size 'n' and n elements of the same array. 2. You are required to find and print all the subarrays of the given array. 3. Each subarray should be space seperated and on a seperate lines. Refer to sample input and output.

`{"id":"2c837aca-7cae-4c0a-8b39-380b38d28eb8","name":"Subarray Problem","description":"1. You are given an array of size 'n' and n elements of the same array.\r\n2. You are required to find and print all the subarrays of the given array. \r\n3. Each subarray should be space seperated and on a seperate lines. Refer to sample input and output.","inputFormat":"A number n\r\nn1\r\nn2\r\n.. n number of elements","outputFormat":"[Tab separated elements of subarray]\r\n..\r\nAll subarrays","constraints":"1 &lt;= n &lt;= 10\r\n0 &lt;= n1, n2\r\n .. n elements &lt;= 10 ^9","sampleCode":{"cpp":{"code":"#include<iostream>\r\nusing namespace std;\r\n\r\n\r\nint main(){\r\n int n;\r\n cin>>n;\r\n int* arr = new int[n];\r\n for(int i = 0 ; i < n; i++){\r\n cin>>arr[i];\r\n }\r\n \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":"n=int(input())\narr=[]\nfor i in range(n):\n val=int(input())\n arr.append(val)\n\n# write your code here"}},"points":10,"difficulty":"easy","sampleInput":"3\r\n10\r\n20\r\n30","sampleOutput":"10\t\r\n10\t20\t\r\n10\t20\t30\t\r\n20\t\r\n20\t30\t\r\n30\t\r\n\r\n","questionVideo":"https://www.youtube.com/embed/YrE8E1J_rp4","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":"f10b54f1-0f44-408f-82d5-89c189f4ad57","name":"Function and Arrays","slug":"function-and-arrays","type":0},{"id":"9035b424-2c38-4f70-8778-6fc638133a3c","name":"Subarray Problem","slug":"subarray-problem","type":1}],"next":{"id":"04d40c08-6f5b-4e5e-9f51-c65f2ffd379b","name":"Sub Arrays Of An Array","type":3,"slug":"sub-arrays-of-an-array"},"prev":{"id":"1cd0ced2-fd4e-44db-85fa-c1ccba0629b3","name":"Inverse Of An Array","type":3,"slug":"inverse-of-an-array"}}}`

Editor

# Subarray Problem

easy

1. You are given an array of size 'n' and n elements of the same array. 2. You are required to find and print all the subarrays of the given array. 3. Each subarray should be space seperated and on a seperate lines. Refer to sample input and output.

## Constraints

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

## Format

### Input

A number n n1 n2 .. n number of elements

### Output

[Tab separated elements of subarray] .. All subarrays

## 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;}3 10 20 30```

### 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;}10 10 20 10 20 30 20 20 30 30 ```

Question Video

Discussions

Show Discussion

Related Resources