@@ -0,0 +1,1347 @@
+/*%0A Given an array of n integers where n %3E 1, nums, return an array output such that output%5Bi%5D is equal to the product of all the elements of nums except nums%5Bi%5D.%0A%0ASolve it without division and in O(n).%0A%0AFor example, given %5B1,2,3,4%5D, return %5B24,12,8,6%5D.%0A%0AFollow up:%0ACould you solve it with constant space complexity? (Note: The output array does not count as extra space for the purpose of space complexity analysis.)%0A*/%0A%0Aimport java.util.*;%0A%0Apublic class ProductofArrayExceptSelf %7B%0A%09public static int%5B%5D productExceptSelf(int%5B%5D nums) %7B%0A        int%5B%5D res = new int%5Bnums.length%5D;%0A        if(nums.length %3C= 0) return res;%0A        int L = nums.length;%0A        int lp = 1, rp = 1;%0A        res%5B0%5D = 1;%0A        for(int i = 1; i %3C L; i++)%7B%0A            lp = lp * nums%5Bi-1%5D;%0A            res%5Bi%5D = lp;%0A        %7D%0A        for(int i = L-2; i %3E= 0; i--)%7B%0A            rp = rp * nums%5Bi+1%5D;%0A            res%5Bi%5D *= rp;%0A        %7D%0A        return res;%0A        %0A    %7D%0A%09public static void main(String%5B%5D args) %7B%0A%09%09int%5B%5D nums1 = new int%5B%5D %7B1,2, 3, 4%7D;%0A        System.out.println(%22Array: %22);%0A%09%09for(int i=0; i %3C nums1.length; i++)%7B%0A%09%09%09System.out.print(nums1%5Bi%5D + %22 %22);%0A%09%09%7D%0A        System.out.println();%0A%09%09int%5B%5D res = productExceptSelf(nums1);%0A        System.out.println(%22Products: %22);%0A%09%09for(int i=0; i %3C res.length; i++)%7B%0A%09%09%09System.out.print(res%5Bi%5D + %22 %22);%0A%09%09%7D%0A%09%09return;%0A%09%7D%09%0A%7D%0A

product of array