Compute Beauty of Array Products
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.
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!
1Example 1
