More
Blog
Series
Projects
About
Leetcode Practice

LC 238. Product of Array Except Self

Last updated
March 2, 2024
Reading time
1 min read
  • Back to start


  • 1. Two Sum


  • 2. Add Two Numbers


  • 3. Longest Substring Without Repeating Characters


  • 7. Reverse Integer


  • 9. Palindrome Number


  • 13. Roman to Integer


  • 15. 3Sum


  • 20. Valid Parentheses


  • 22. Generate Parentheses


  • 36. Valid Sudoku


  • 49. Group Anagrams


  • 84. Largest Rectangle in Histogram


  • 88. Merge Sorted Array


  • 125. Valid Palindrome


  • 150. Evaluate Reverse Polish Notation


  • 151. Min Stack


  • 217. Contains Duplicate


  • 238. Product of Array Except Self


  • 242. Valid Anagram


  • 347. Top K Frequent Elements


  • 424. Longest Repeating Character Replacement


  • 496. Next Greater Element I


  • 503. Next Greater Element II


  • 704. Binary Search


  • 739. Daily Temperatures


  • 853. Car Fleet


  • 875. Koko Eating Bananas


  • 901. Online Stock Span


  • 1431. Kids with the Greatest Number of Candies


  • 1475. Final Prices with a Special Discount in a Shop


  • 1832. Check if the Sentence in Pangram


  • 2582. Pass the Pillow

The problem

First Solution

function productExceptSelf(nums: number[]): number[] {
  let arr = []
  let currentProduct = 1
  for (let i = 0; i < nums.length; i++) {
    arr.push(currentProduct)
    currentProduct *= nums[i]
  }

  currentProduct = 1
  for (let i = nums.length - 1; i >= 0; i--) {
    arr[i] *= currentProduct
    currentProduct *= nums[i]
  }

  return arr
}
Previous217. Contains Duplicate
Next242. Valid Anagram
githubfacebookyoutubelinkedintwitter
Hunter Faulkner
•
© 2025
•
Phantom Draught
Yokai icons created by Freepik • Flaticon