{"id":"da1064e1-970d-4d65-b565-28032e3e5ac0","name":"Inverse Of 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 calculate the inverse of array a.\r\n\r\nFor definition and constraints check this link\r\nhttps://www.pepcoding.com/resources/online-java-foundation/getting-started/inverse-of-a-number/ojquestion\r\nThe only difference is the range of values is from 0 to n - 1, instead of 1 to n.","inputFormat":"Input is managed for you\r\n","outputFormat":"Output is managed for you\r\n","constraints":"0 &lt;= n &lt; 10^7\r\nFor more constraints check this\r\nhttps://www.pepcoding.com/resources/online-java-foundation/getting-started/inverse-of-a-number/ojquestion\r\nThe only difference is the range of values is from 0 to n - 1, instead\r\nof 1 to n","sampleCode":{"cpp":{"code":"#include<iostream>\r\nusing namespace std;\r\n\r\nint* inverse(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]<<endl;\r\n }\r\n cout<<endl;\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 int* inv = inverse(arr,n);\r\n display(inv,n);\r\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 + \"\\n\");\r\n }\r\n System.out.println(sb);\r\n }\r\n\r\n public static int[] inverse(int[] a){\r\n // write your code here\r\n return null;\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 int[] inv = inverse(a);\r\n display(inv);\r\n }\r\n\r\n}"},"python":{"code":"def inverse(a,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 = inverse(arr,n)\n for i in range(n):\n print(arr[i])\n\nmain()"}},"points":10,"difficulty":"easy","sampleInput":"5\r\n4\r\n0\r\n2\r\n3\r\n1","sampleOutput":"1\r\n4\r\n2\r\n3\r\n0","questionVideo":"https://www.youtube.com/embed/TCDPgRgCNr0","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":"0bb15817-e2fb-429e-b3c8-2db78fd476cf","name":"Inverse Of An Array","slug":"inverse-of-an-array","type":1}],"next":{"id":"1cd0ced2-fd4e-44db-85fa-c1ccba0629b3","name":"Inverse Of An Array","type":3,"slug":"inverse-of-an-array"},"prev":{"id":"06b6254b-96ff-439b-b09c-38c6a8ea3fa4","name":"Rotate an Array","type":3,"slug":"rotate-an-array"}}}

Inverse Of 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 calculate the inverse of array a. For definition and constraints check this link https://www.pepcoding.com/resources/online-java-foundation/getting-started/inverse-of-a-number/ojquestion The only difference is the range of values is from 0 to n - 1, instead of 1 to n.

{"id":"da1064e1-970d-4d65-b565-28032e3e5ac0","name":"Inverse Of 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 calculate the inverse of array a.\r\n\r\nFor definition and constraints check this link\r\nhttps://www.pepcoding.com/resources/online-java-foundation/getting-started/inverse-of-a-number/ojquestion\r\nThe only difference is the range of values is from 0 to n - 1, instead of 1 to n.","inputFormat":"Input is managed for you\r\n","outputFormat":"Output is managed for you\r\n","constraints":"0 &lt;= n &lt; 10^7\r\nFor more constraints check this\r\nhttps://www.pepcoding.com/resources/online-java-foundation/getting-started/inverse-of-a-number/ojquestion\r\nThe only difference is the range of values is from 0 to n - 1, instead\r\nof 1 to n","sampleCode":{"cpp":{"code":"#include<iostream>\r\nusing namespace std;\r\n\r\nint* inverse(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]<<endl;\r\n }\r\n cout<<endl;\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 int* inv = inverse(arr,n);\r\n display(inv,n);\r\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 + \"\\n\");\r\n }\r\n System.out.println(sb);\r\n }\r\n\r\n public static int[] inverse(int[] a){\r\n // write your code here\r\n return null;\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 int[] inv = inverse(a);\r\n display(inv);\r\n }\r\n\r\n}"},"python":{"code":"def inverse(a,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 = inverse(arr,n)\n for i in range(n):\n print(arr[i])\n\nmain()"}},"points":10,"difficulty":"easy","sampleInput":"5\r\n4\r\n0\r\n2\r\n3\r\n1","sampleOutput":"1\r\n4\r\n2\r\n3\r\n0","questionVideo":"https://www.youtube.com/embed/TCDPgRgCNr0","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":"0bb15817-e2fb-429e-b3c8-2db78fd476cf","name":"Inverse Of An Array","slug":"inverse-of-an-array","type":1}],"next":{"id":"1cd0ced2-fd4e-44db-85fa-c1ccba0629b3","name":"Inverse Of An Array","type":3,"slug":"inverse-of-an-array"},"prev":{"id":"06b6254b-96ff-439b-b09c-38c6a8ea3fa4","name":"Rotate an Array","type":3,"slug":"rotate-an-array"}}}
plane

Editor


Loading...

Inverse Of 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 calculate the inverse of array a. For definition and constraints check this link https://www.pepcoding.com/resources/online-java-foundation/getting-started/inverse-of-a-number/ojquestion The only difference is the range of values is from 0 to n - 1, instead of 1 to n.

Constraints

0 <= n < 10^7 For more constraints check this https://www.pepcoding.com/resources/online-java-foundation/getting-started/inverse-of-a-number/ojquestion The only difference is the range of values is from 0 to n - 1, instead of 1 to n

Format

Input

Input is managed for you

Output

Output is managed for you

Example

Sample Input

5 4 0 2 3 1

Sample Output

1 4 2 3 0

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode