Wawancara 150 TeratasKeras

Subarray Produk Maksimum

Panduan terperinci dan implementasi Python untuk masalah 'Subarray Produk Maksimum'.

Pernyataan Masalah

Keras

Mengingat jumlah array bilangan bulat, temukan subarray tidak kosong yang berdekatan dalam array yang memiliki produk terbesar, dan kembalikan produk tersebut.

Kasus uji dibuat sehingga jawabannya sesuai dengan bilangan bulat 32-bit.

Tulis fungsi maxProduct(nums: List[int]) -> int.

Kendala
  • 1 <= len(nums) <= 2 * 10^4
  • -10 <= nums[i] <= 10
  • The product of any prefix or suffix of nums fits in a 32-bit integer

Contoh

Example 1
Input
nums = [2,3,-2,4]
Output
6
Explanation

[2,3] has the largest product 6.

Example 2
Input
nums = [-2,0,-1]
Output
0
Explanation

The result cannot be larger than 0 because of the negative numbers separated by 0.

Need a Hint?
Pertimbangkan untuk menggunakan struktur data khusus DP 1D seperti kumpulan atau tumpukan.
Edge Cases to Watch
  • Struktur masukan kosong
  • Masukan elemen tunggal
  • Batasan angka yang besar

Siap Memecahkannya?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Buka di Editor
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

Sumber Daya Python yang Direkomendasikan

Perluas pengetahuan Anda dengan tutorial interaktif terkait, lembar contekan, dan perbandingan kode.