←ENG-DSA-061Cross-Sell Recommendation Scoring (Prefix/Suffix Arrays)
00:00
🐍 Python Idle
Mode:Web

Cross-Sell Recommendation Scoring (Prefix/Suffix Arrays)

CompaniesAmazon, Instacart
Est. Time~30 min
LevelMid
ArraysMathPrefix Sum
🚨 P0 Incident
AmazonInstacart

In e-commerce recommendation models like Naive Bayes, calculating the combined probability of "all other items EXCEPT this one" is required to find conditional independence. If the array contains probability scores, division is mathematically risky due to floating point zeroes. We need to compute the product of all elements except 'i' without using division.

πŸ“₯ Assigned to:You β€” Mid Engineer
Your Task

Given an integer array `nums`, return an array `answer` such that `answer[i]` is equal to the product of all the elements of `nums` except `nums[i]`. You must write an algorithm that runs in O(N) time and without using the division operation.

⏱ Time: O(N)πŸ’Ύ Space: O(1) excluding output array
Example 1
Input:Β Β nums=[1, 2, 3, 4]
Output:Β [24, 12, 8, 6]
Example 2
Input:Β Β nums=[-1, 1, 0, -3, 3]
Output:Β [0, 0, 9, 0, 0]
πŸ”’ +3 hidden test cases β€” revealed on Submit
Hints
Loading editor…
Test Output
β–Ά Run Code to test against examples Β· Submit to judge all 5 test cases
EngPrep β€” Real Engineering. Real Interviews.