{"id":"0078fd6e-a259-408a-9e38-e6fe15da83ff","name":"Reverse An Array","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 reverse the contents of array a.","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"0 &lt;= n &lt; 10^4\r\n-10^9 &lt;= a[i] &lt;= 10^9","sampleCode":{"cpp":{"code":"#include<iostream>\r\nusing namespace std;\r\n\r\nvoid reverse(int* arr, int n){\r\n // write your code here\r\n \r\n}\r\n\r\nvoid display(int* arr, int n){\r\n for(int i = 0 ; i < n; i++){\r\n cout<<arr[i]<<\" \";\r\n }\r\n cout<<endl;\r\n}\r\n\r\nint main(){\r\n int n;\r\n cin>>n;\r\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 reverse(arr,n);\r\n display(arr,n);\r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main{\r\n public static void display(int[] a){\r\n StringBuilder sb = new StringBuilder();\r\n\r\n for(int val: a){\r\n sb.append(val + \" \");\r\n }\r\n System.out.println(sb);\r\n }\r\n\r\n public static void reverse(int[] a){\r\n // write your code here\r\n }\r\n\r\npublic static void main(String[] args) throws Exception {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n int n = Integer.parseInt(br.readLine());\r\n int[] a = new int[n];\r\n for(int i = 0; i < n; i++){\r\n a[i] = Integer.parseInt(br.readLine());\r\n }\r\n\r\n reverse(a);\r\n display(a);\r\n }\r\n\r\n}"},"python":{"code":"def reverse(arr,n):\n # write your code here\n \ndef main():\n n=int(input())\n arr=[]\n for i in range(n):\n val=int(input())\n arr.append(val)\n arr = reverse(arr,n)\n for i in range(n):\n print(arr[i],end=\" \")\n\nmain()"}},"points":10,"difficulty":"easy","sampleInput":"5\r\n1\r\n2\r\n3\r\n4\r\n5","sampleOutput":"5 4 3 2 1","questionVideo":"https://www.youtube.com/embed/RJITdlWR1-g","hints":[],"associated":[{"id":"89f610db-13e0-4279-99a3-abba7edfb1de","name":"(Reverse an array) When array reversal and rotation is applied to the same array then the output produced will also be the same every time.","slug":"reverse-an-array-when-array-reversal-and-rotation-is-applied-to-the-same-array-then-the-output-produced-will-also-be-the-same-every-time","type":4},{"id":"a3d8ecbd-0edb-4a53-8159-b54f8734d966","name":"(Reverse an array) Which of the following is the predefined function for array reversal in C++?","slug":"reverse-an-array-which-of-the-following-is-the-predefined-function-for-array-reversal-in-c","type":4},{"id":"ba13e6d3-eef5-495f-a000-7ed110f80d80","name":"(Reverse an array) How many swaps are required for reversing an array having n elements where n is an even number?","slug":"reverse-an-array-how-many-swaps-are-required-for-reversing-an-array-having-n-elements-where-n-is-an-even-number","type":4},{"id":"fd995a53-aaf2-4e4c-9198-ca280006efd3","name":"(reverse an array) How many swaps are required for reversing an array having n elements where n is an odd number?","slug":"reverse-an-array-how-many-swaps-are-required-for-reversing-an-array-having-n-elements-where-n-is-an-odd-number","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":"f36071f6-11dc-4d7c-b532-3792754623a9","name":"Reverse An Array","slug":"reverse-an-array","type":1}],"next":{"id":"21bceb6d-67d7-4cd0-bcd8-4fd0de44363d","name":"Reverse an Array","type":3,"slug":"reverse-an-array"},"prev":{"id":"6e7882be-7546-4ccc-9c05-9a6e285e127f","name":"Difference Of Two Arrays","type":3,"slug":"difference-of-two-arrays"}}}

Reverse An Array

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 reverse the contents of array a.

{"id":"0078fd6e-a259-408a-9e38-e6fe15da83ff","name":"Reverse An Array","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 reverse the contents of array a.","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"0 &lt;= n &lt; 10^4\r\n-10^9 &lt;= a[i] &lt;= 10^9","sampleCode":{"cpp":{"code":"#include<iostream>\r\nusing namespace std;\r\n\r\nvoid reverse(int* arr, int n){\r\n // write your code here\r\n \r\n}\r\n\r\nvoid display(int* arr, int n){\r\n for(int i = 0 ; i < n; i++){\r\n cout<<arr[i]<<\" \";\r\n }\r\n cout<<endl;\r\n}\r\n\r\nint main(){\r\n int n;\r\n cin>>n;\r\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 reverse(arr,n);\r\n display(arr,n);\r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main{\r\n public static void display(int[] a){\r\n StringBuilder sb = new StringBuilder();\r\n\r\n for(int val: a){\r\n sb.append(val + \" \");\r\n }\r\n System.out.println(sb);\r\n }\r\n\r\n public static void reverse(int[] a){\r\n // write your code here\r\n }\r\n\r\npublic static void main(String[] args) throws Exception {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n int n = Integer.parseInt(br.readLine());\r\n int[] a = new int[n];\r\n for(int i = 0; i < n; i++){\r\n a[i] = Integer.parseInt(br.readLine());\r\n }\r\n\r\n reverse(a);\r\n display(a);\r\n }\r\n\r\n}"},"python":{"code":"def reverse(arr,n):\n # write your code here\n \ndef main():\n n=int(input())\n arr=[]\n for i in range(n):\n val=int(input())\n arr.append(val)\n arr = reverse(arr,n)\n for i in range(n):\n print(arr[i],end=\" \")\n\nmain()"}},"points":10,"difficulty":"easy","sampleInput":"5\r\n1\r\n2\r\n3\r\n4\r\n5","sampleOutput":"5 4 3 2 1","questionVideo":"https://www.youtube.com/embed/RJITdlWR1-g","hints":[],"associated":[{"id":"89f610db-13e0-4279-99a3-abba7edfb1de","name":"(Reverse an array) When array reversal and rotation is applied to the same array then the output produced will also be the same every time.","slug":"reverse-an-array-when-array-reversal-and-rotation-is-applied-to-the-same-array-then-the-output-produced-will-also-be-the-same-every-time","type":4},{"id":"a3d8ecbd-0edb-4a53-8159-b54f8734d966","name":"(Reverse an array) Which of the following is the predefined function for array reversal in C++?","slug":"reverse-an-array-which-of-the-following-is-the-predefined-function-for-array-reversal-in-c","type":4},{"id":"ba13e6d3-eef5-495f-a000-7ed110f80d80","name":"(Reverse an array) How many swaps are required for reversing an array having n elements where n is an even number?","slug":"reverse-an-array-how-many-swaps-are-required-for-reversing-an-array-having-n-elements-where-n-is-an-even-number","type":4},{"id":"fd995a53-aaf2-4e4c-9198-ca280006efd3","name":"(reverse an array) How many swaps are required for reversing an array having n elements where n is an odd number?","slug":"reverse-an-array-how-many-swaps-are-required-for-reversing-an-array-having-n-elements-where-n-is-an-odd-number","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":"f36071f6-11dc-4d7c-b532-3792754623a9","name":"Reverse An Array","slug":"reverse-an-array","type":1}],"next":{"id":"21bceb6d-67d7-4cd0-bcd8-4fd0de44363d","name":"Reverse an Array","type":3,"slug":"reverse-an-array"},"prev":{"id":"6e7882be-7546-4ccc-9c05-9a6e285e127f","name":"Difference Of Two Arrays","type":3,"slug":"difference-of-two-arrays"}}}
plane

Editor


Loading...

Reverse An Array

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 reverse the contents of array a.

Constraints

0 <= n < 10^4 -10^9 <= a[i] <= 10^9

Format

Input

Input is managed for you

Output

Output is managed for you

Example

Sample Input

5 1 2 3 4 5

Sample Output

5 4 3 2 1

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode