Given an array of integers and a number k, find the length of the longest subarray where the product of all elements is less than or equal to k.
Explanation: Step-by-step: We start with the subarray [1, 2, 3, 4, 5]. The product of this subarray is 120 which is greater than k=100. We move the left pointer to the right until the product of the subarray is less than or equal to k. The longest subarray with product <= k is [1, 2, 3] with product 6 which is <= k.
Explanation: Step-by-step: We start with the subarray [5, 5, 5, 5, 5, 25]. The product of this subarray is 3125 which is greater than k=25. We move the left pointer to the right until the product of the subarray is less than or equal to k. The longest subarray with product <= k is [5] with product 5 which is <= k.
Master coding challenges related to Arrays and solve the [Backup] Consecutive Subarray Product problem optimally.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak