`{"id":"47ad10ba-a3de-4c45-afbf-78dfbf6906c9","name":"Display Array In Reverse","description":"1. You are given a number n, representing the size of array a.\r\n2. You are given n numbers, representing elements of array a.\r\n3. You are required to print the elements of array from end to beginning each in a separate line.\r\n4. For the above purpose complete the body of displayArrReverse 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":"n1\r\nn2\r\n.. n elements","constraints":"1 &lt;= n &lt;= 30\r\n0 &lt;= n1, n2, .. n elements &lt;= 10","sampleCode":{"cpp":{"code":"#include <iostream>\r\nusing namespace std;\r\n\r\nvoid display(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 display(arr, 0, n);\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 void displayArrReverse(int[] arr, int idx) {\r\n\r\n }\r\n\r\n}"},"python":{"code":"def displayinrev(arr,idx,n):\n \n # Write your code here\n\ndef main():\n n=int(input())\n arr=[]\n for i in range(n):\n arr.append(int(input()))\n displayinrev(arr,0,n)\nmain()"}},"points":10,"difficulty":"easy","sampleInput":"5\r\n3\r\n1\r\n0\r\n7\r\n5","sampleOutput":"5\r\n7\r\n0\r\n1\r\n3","questionVideo":"https://www.youtube.com/embed/_O6geLdoSV4","hints":[],"associated":[{"id":"2b793517-5722-4eca-8b5a-c9b1e37ac59b","name":"(Display array in reverse) What will be the time complexity of the program?","slug":"display-array-in-reverse-what-will-be-the-time-complexity-of-the-program","type":4},{"id":"472fd30a-f563-44c0-92fc-1423e7e1fe39","name":"(Display array in reverse) What should be the base condition of recursive function?","slug":"display-array-in-reverse-what-should-be-the-base-condition-of-recursive-function","type":4},{"id":"6e7e1c34-c134-49c3-91f2-f9fe31457de8","name":"(Display array in reverse) What will be the resulting array after reversing arr[]={3,5,4,2}?","slug":"display-array-in-reverse-what-will-be-the-resulting-array-after-reversing-arr-3-5-4-2","type":4},{"id":"ec863fe7-c5b6-4321-bb34-197614c26194","name":"(Display array in reverse) What will be the faith in the recursive call?","slug":"display-array-in-reverse-what-will-be-the-faith-in-the-recursive-call","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":"427426a2-6937-4194-acc6-7bd7ebd03953","name":"Display Array In Reverse","slug":"display-array-in-reverse","type":1}],"next":{"id":"6c14b3f0-23c0-4692-9b00-7fd245e551bf","name":"Display Array Reverse","type":3,"slug":"display-array-reverse"},"prev":{"id":"8b0857ed-4ab5-4790-aabb-3554c404b155","name":"Display Array","type":3,"slug":"display-array"}}}`

Display Array In Reverse

1. You are given a number n, representing the size of array a. 2. You are given n numbers, representing elements of array a. 3. You are required to print the elements of array from end to beginning each in a separate line. 4. For the above purpose complete the body of displayArrReverse 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":"47ad10ba-a3de-4c45-afbf-78dfbf6906c9","name":"Display Array In Reverse","description":"1. You are given a number n, representing the size of array a.\r\n2. You are given n numbers, representing elements of array a.\r\n3. You are required to print the elements of array from end to beginning each in a separate line.\r\n4. For the above purpose complete the body of displayArrReverse 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":"n1\r\nn2\r\n.. n elements","constraints":"1 &lt;= n &lt;= 30\r\n0 &lt;= n1, n2, .. n elements &lt;= 10","sampleCode":{"cpp":{"code":"#include <iostream>\r\nusing namespace std;\r\n\r\nvoid display(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 display(arr, 0, n);\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 void displayArrReverse(int[] arr, int idx) {\r\n\r\n }\r\n\r\n}"},"python":{"code":"def displayinrev(arr,idx,n):\n \n # Write your code here\n\ndef main():\n n=int(input())\n arr=[]\n for i in range(n):\n arr.append(int(input()))\n displayinrev(arr,0,n)\nmain()"}},"points":10,"difficulty":"easy","sampleInput":"5\r\n3\r\n1\r\n0\r\n7\r\n5","sampleOutput":"5\r\n7\r\n0\r\n1\r\n3","questionVideo":"https://www.youtube.com/embed/_O6geLdoSV4","hints":[],"associated":[{"id":"2b793517-5722-4eca-8b5a-c9b1e37ac59b","name":"(Display array in reverse) What will be the time complexity of the program?","slug":"display-array-in-reverse-what-will-be-the-time-complexity-of-the-program","type":4},{"id":"472fd30a-f563-44c0-92fc-1423e7e1fe39","name":"(Display array in reverse) What should be the base condition of recursive function?","slug":"display-array-in-reverse-what-should-be-the-base-condition-of-recursive-function","type":4},{"id":"6e7e1c34-c134-49c3-91f2-f9fe31457de8","name":"(Display array in reverse) What will be the resulting array after reversing arr[]={3,5,4,2}?","slug":"display-array-in-reverse-what-will-be-the-resulting-array-after-reversing-arr-3-5-4-2","type":4},{"id":"ec863fe7-c5b6-4321-bb34-197614c26194","name":"(Display array in reverse) What will be the faith in the recursive call?","slug":"display-array-in-reverse-what-will-be-the-faith-in-the-recursive-call","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":"427426a2-6937-4194-acc6-7bd7ebd03953","name":"Display Array In Reverse","slug":"display-array-in-reverse","type":1}],"next":{"id":"6c14b3f0-23c0-4692-9b00-7fd245e551bf","name":"Display Array Reverse","type":3,"slug":"display-array-reverse"},"prev":{"id":"8b0857ed-4ab5-4790-aabb-3554c404b155","name":"Display Array","type":3,"slug":"display-array"}}}`

Editor

Display Array In Reverse

easy

1. You are given a number n, representing the size of array a. 2. You are given n numbers, representing elements of array a. 3. You are required to print the elements of array from end to beginning each in a separate line. 4. For the above purpose complete the body of displayArrReverse 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 <= 30 0 <= n1, n2, .. n elements <= 10

Format

Input

A number n n1 n2 .. n number of elements

Output

n1 n2 .. n elements

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;}5 3 1 0 7 5```

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;}5 7 0 1 3```

Question Video

Discussions

Show Discussion

Related Resources