class Solution { public: vector productExceptSelf(vector& nums) { // Compute the Suffix Array // Preprocessing stage int n = nums.size(), p = 1, i; // Declare an integer array of size n vector suff(n, 0); for(i = n-1; i >= 0; i--){ p = p*nums[i]; suff[i] = p; } // Actual computation // Declare the result array vector res(n, 0); p = 1; for(i = 0; i < n-1; i++){ res[i] = p*suff[i+1]; p = p*nums[i]; } res[n-1] = p; return res; } };