Sign In
You are coding as a Guest. Sign in with your RoleNest account to permanently track your streak, earn XP, and climb the Campus Leaderboard!
Sign In with RoleNest
🔥Product of Array Except SelfMedium
DAILY PROBLEM OF THE DAY+50 XP • Daily Streak

Solve today's challenge or tackle one of the 3 Super Hard challenges for +150 XP.

MediumArrays & Hashing•Acceptance: 65.4%

Product of Array Except Self

Targeted in FAANG & Tech OA:AmazonMicrosoftAppleUber
Real-World Engineering Context
Critical in portfolio risk analytics and stock volatility recalculation where removing one asset's variance must be calculated without recomputing full matrix products.
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]`. The algorithm must run in O(n) time without using the division operation.

Sample Test Cases

Input: [[1,2,3,4]]
Expected: [24,12,8,6]
Input: [[-1,1,0,-3,3]]
Expected: [0,0,9,0]
Input: [[2,3]]
Expected: [3,2]

Constraints

  • 2 <= nums.length <= 10^5
  • -30 <= nums[i] <= 30
  • The product of any prefix or suffix of nums fits in a 32-bit integer.
Recruiter Fast-Track ReferralVerified Candidate
Direct pipeline to Google, Amazon, Microsoft, Swiggy, & Uber recruiters
DevScore: 750/1000

Top DevScore profiles bypass resume screening filters. Every verified problem solve writes authentic proof-of-work to your profile and dispatches you directly into employer inboxes on RoleNest.