Compute Beauty of Array Products
Learn this problemProblem statement
The Amazon distribution center consists of arrays of products, each possessing unique attributes. The task at hand is to compute the beauty of these product arrays, with the goal of achieving an efficient selection process.
More specifically, there are arrays of products, and each array corresponds to a list of attributes. The beauty of a subarray B = [products[l], products[l+1], ..., products[r]] is quantified by counting the indices i that satisfy these conditions:
An array B is a subarray of an array A if B can be obtained from A by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.
The beautiness of the entire array of products is determined by the sum of beauty values across all subarrays of a given size k.
Given an array products of size n and an integer k. Compute the total beautiness of the array of products.
Function
computeBeauty(products: int[], k: int) → int
Complete the function computeBeauty in the editor.
computeBeauty has the following parameters:
- 1.
int[] products: an array of integers representing the products - 2.
int k: the size of the subarray
Returns
int: the total beautiness of the array of products
💜 Endlessly grateful to the amazing friend for their help!
Examples
Example 1
products = [3, 6, 2, 9, 4, 1]k = 3return = 8
More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026