{"id":"15952c2c-0266-44aa-a764-53a93d600923","name":"Product Of Array Except Itself Without Using Division Operator","description":"1. Given an integer array of size 'n'.\r\n2. Return an array answer such that answer[i] is equal to the product of all the elements of arr except arr[i].\r\n3. The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.\r\n","inputFormat":"N -> size of array.\r\nN distinct elements n0 n1, n2, . , . , . nN.\r\n","outputFormat":"print Final res\r\n","constraints":"1. 2 &lt;= arr.length &lt;= 10^5\r\n2. -30 &lt;= arr[i] &lt;= 30\r\n3. The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.\r\n","sampleCode":{"cpp":{"code":"#include <iostream>\n#include <vector>\nusing namespace std;\nvector<int> productExceptSelf(vector<int> &arr) {\n // write your code here\n return null;\n}\nint main() {\n // Input\n int n=0;\n cin>>n;\n vector<int> arr(n);\n for(int i = 0; i < n; i++) {\n cin>>arr[i];\n }\n vector<int> res = productExceptSelf(arr);\n for(int i = 0; i < res.size(); i++) {\n cout<<res[i]<<\" \";\n }\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n \r\n //~~~~~~~~~~~~~~~~~User Section~~~~~~~~~~~~~~~\r\n public static int[] productExceptSelf(int[] arr) {\r\n // write your code here\r\n }\r\n\r\n //~~~~~~~~~~~~~~~~~Input Management~~~~~~~~~~~~~~~\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[] arr = new int[n];\r\n for(int i = 0; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n int[] res = productExceptSelf(arr);\r\n for(int i = 0; i < arr.length; i++) {\r\n System.out.print(res[i] + \" \");\r\n }\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"4\r\n1 2 3 4","sampleOutput":"24 12 8 6","questionVideo":"","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":"35f2cfb0-6f25-4967-b0c9-92f2384b9260","name":"Arrays And Strings For Intermediate","slug":"arrays-and-strings-for-intermediate-732","type":0},{"id":"b61afd8c-673e-4976-b567-909f08b3029c","name":"Product Of Array Except Itself Without Using Division Operator","slug":"product-of-array-except-itself-without-using-division-operator","type":1}],"next":{"id":"2bc67870-4776-48a4-8d28-127657a82002","name":"Product of array except itself without using division operator","type":3,"slug":"product-of-array-except-itself-without-using-division-operator"},"prev":{"id":"f4b4461e-5080-45b0-95f3-4d82b0836ca7","name":"Range Addition MCQ","type":0,"slug":"range-addition-mcq"}}}

Product Of Array Except Itself Without Using Division Operator

1. Given an integer array of size 'n'. 2. Return an array answer such that answer[i] is equal to the product of all the elements of arr except arr[i]. 3. The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.

{"id":"15952c2c-0266-44aa-a764-53a93d600923","name":"Product Of Array Except Itself Without Using Division Operator","description":"1. Given an integer array of size 'n'.\r\n2. Return an array answer such that answer[i] is equal to the product of all the elements of arr except arr[i].\r\n3. The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.\r\n","inputFormat":"N -> size of array.\r\nN distinct elements n0 n1, n2, . , . , . nN.\r\n","outputFormat":"print Final res\r\n","constraints":"1. 2 &lt;= arr.length &lt;= 10^5\r\n2. -30 &lt;= arr[i] &lt;= 30\r\n3. The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.\r\n","sampleCode":{"cpp":{"code":"#include <iostream>\n#include <vector>\nusing namespace std;\nvector<int> productExceptSelf(vector<int> &arr) {\n // write your code here\n return null;\n}\nint main() {\n // Input\n int n=0;\n cin>>n;\n vector<int> arr(n);\n for(int i = 0; i < n; i++) {\n cin>>arr[i];\n }\n vector<int> res = productExceptSelf(arr);\n for(int i = 0; i < res.size(); i++) {\n cout<<res[i]<<\" \";\n }\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n \r\n //~~~~~~~~~~~~~~~~~User Section~~~~~~~~~~~~~~~\r\n public static int[] productExceptSelf(int[] arr) {\r\n // write your code here\r\n }\r\n\r\n //~~~~~~~~~~~~~~~~~Input Management~~~~~~~~~~~~~~~\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[] arr = new int[n];\r\n for(int i = 0; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n int[] res = productExceptSelf(arr);\r\n for(int i = 0; i < arr.length; i++) {\r\n System.out.print(res[i] + \" \");\r\n }\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"4\r\n1 2 3 4","sampleOutput":"24 12 8 6","questionVideo":"","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":"35f2cfb0-6f25-4967-b0c9-92f2384b9260","name":"Arrays And Strings For Intermediate","slug":"arrays-and-strings-for-intermediate-732","type":0},{"id":"b61afd8c-673e-4976-b567-909f08b3029c","name":"Product Of Array Except Itself Without Using Division Operator","slug":"product-of-array-except-itself-without-using-division-operator","type":1}],"next":{"id":"2bc67870-4776-48a4-8d28-127657a82002","name":"Product of array except itself without using division operator","type":3,"slug":"product-of-array-except-itself-without-using-division-operator"},"prev":{"id":"f4b4461e-5080-45b0-95f3-4d82b0836ca7","name":"Range Addition MCQ","type":0,"slug":"range-addition-mcq"}}}
plane

Editor


Loading...

Product Of Array Except Itself Without Using Division Operator

easy

1. Given an integer array of size 'n'. 2. Return an array answer such that answer[i] is equal to the product of all the elements of arr except arr[i]. 3. The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.

Constraints

1. 2 <= arr.length <= 10^5 2. -30 <= arr[i] <= 30 3. The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.

Format

Input

N -> size of array. N distinct elements n0 n1, n2, . , . , . nN.

Output

print Final res

Example

Sample Input

4 1 2 3 4

Sample Output

24 12 8 6

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode