PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Amazon

Compute array products excluding self and top-k

Last updated: Mar 29, 2026

Quick Overview

This question evaluates skills in array manipulation, in-place algorithm design, numerical stability and edge-case reasoning (such as handling multiple zeros and large products), plus selection and ranking competencies for extracting the top-k elements.

  • medium
  • Amazon
  • Coding & Algorithms
  • Machine Learning Engineer

Compute array products excluding self and top-k

Company: Amazon

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

## Algorithms ### 1) Product of array except self (no division) Given an integer array `nums` of length `n`, return an array `ans` where: - `ans[i]` = product of all `nums[j]` for `j != i` - You **must not use division** - Target time: **O(n)** - Extra space: **O(1)** beyond the output array #### Follow-ups - How does your approach handle **many zeros** in the input? - How do you handle **overflow / very large products**? ### 2) Find the k largest elements Given an unsorted array of numbers and an integer `k`, return the **k largest elements** (order does not matter unless specified). Discuss time/space trade-offs for different approaches.

Quick Answer: This question evaluates skills in array manipulation, in-place algorithm design, numerical stability and edge-case reasoning (such as handling multiple zeros and large products), plus selection and ranking competencies for extracting the top-k elements.

Related Interview Questions

  • Find Unique Target-Sum Pairs - Amazon (easy)
  • Find Valid IP Addresses in Files - Amazon (medium)
  • Implement Optimal Bucket Batching - Amazon (hard)
  • Implement Cache and Rotate Matrix - Amazon (medium)
  • Find Longest Activatable Server Streak - Amazon (hard)
Amazon logo
Amazon
Jan 6, 2026, 12:00 AM
Machine Learning Engineer
Onsite
Coding & Algorithms
7
0
Loading...

Algorithms

1) Product of array except self (no division)

Given an integer array nums of length n, return an array ans where:

  • ans[i] = product of all nums[j] for j != i
  • You must not use division
  • Target time: O(n)
  • Extra space: O(1) beyond the output array

Follow-ups

  • How does your approach handle many zeros in the input?
  • How do you handle overflow / very large products ?

2) Find the k largest elements

Given an unsorted array of numbers and an integer k, return the k largest elements (order does not matter unless specified). Discuss time/space trade-offs for different approaches.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Amazon•More Machine Learning Engineer•Amazon Machine Learning Engineer•Amazon Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,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
  • Compare Platforms
  • Discord Community

Support

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

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.