PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Microsoft

Compute the Product of an Array Except Self

Last updated: Jul 9, 2026

Quick Overview

Tackle the product-of-array-except-self problem under linear-time and constant-auxiliary-space constraints. It assesses array reasoning, careful handling of zeros and negative values, input immutability, complexity analysis, and edge-case discipline.

  • medium
  • Microsoft
  • Coding & Algorithms
  • Data Scientist

Compute the Product of an Array Except Self

Company: Microsoft

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

The interview report preserved the input-output example but not every original restriction. The following is a self-contained version of the reported array-product task. Implement: ```python def product_except_self(nums: list[int]) -> list[int]: ... ``` Given an integer array `nums`, return an array `answer` of the same length such that `answer[i]` is the product of every element of `nums` except `nums[i]`. Do not use division. Your algorithm must run in `O(n)` time and use `O(1)` auxiliary space apart from the returned array. Constraints: - `2 <= len(nums) <= 100_000` - `-30 <= nums[i] <= 30` - Every prefix product, suffix product, and requested output fits in a signed 64-bit integer. - The input may contain zero, multiple zeros, and negative values. - Do not mutate `nums`. Examples: ```text Input: nums = [1, 2, 3, 4] Output: [24, 12, 8, 6] ``` ```text Input: nums = [-1, 1, 0, -3, 3] Output: [0, 0, 9, 0, 0] ```

Quick Answer: Tackle the product-of-array-except-self problem under linear-time and constant-auxiliary-space constraints. It assesses array reasoning, careful handling of zeros and negative values, input immutability, complexity analysis, and edge-case discipline.

Related Interview Questions

  • In-Memory URL Shortener: Encode and Decode - Microsoft (medium)
  • Minimum Moves on a Grid with k-Cell Jumps - Microsoft (medium)
  • Return Top K Open Businesses - Microsoft (hard)
  • Implement Memory Allocation and In-Memory Records - Microsoft (medium)
  • Implement K-Means and Detect Divisible Subarrays - Microsoft (medium)
|Home/Coding & Algorithms/Microsoft

Compute the Product of an Array Except Self

Microsoft logo
Microsoft
May 4, 2026, 12:00 AM
mediumData ScientistTechnical ScreenCoding & Algorithms
0
0

The interview report preserved the input-output example but not every original restriction. The following is a self-contained version of the reported array-product task.

Implement:

def product_except_self(nums: list[int]) -> list[int]:
    ...

Given an integer array nums, return an array answer of the same length such that answer[i] is the product of every element of nums except nums[i].

Do not use division. Your algorithm must run in O(n) time and use O(1) auxiliary space apart from the returned array.

Constraints:

  • 2 <= len(nums) <= 100_000
  • -30 <= nums[i] <= 30
  • Every prefix product, suffix product, and requested output fits in a signed 64-bit integer.
  • The input may contain zero, multiple zeros, and negative values.
  • Do not mutate nums .

Examples:

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

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Microsoft•More Data Scientist•Microsoft Data Scientist•Microsoft Coding & Algorithms•Data Scientist Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.