Description
Solutions
Compressing Array
🔥 FULLTIME📚RELATED PROBLEMS
Given an array of integers, a
, in one operation one can select any two adjacent elements and replace them with their product. This operation can only be applied if the product of those adjacent elements is less than or equal to k
.
The goal is to reduce the length of the array as much as possible by performing any number of operations. Return that minimum size.
Function Description
Complete the function getMinLength
in the editor.
getMinLength
has the following parameters:
int a[n]
: an array of integersint k
: the constraint of the operation
Returns
int: the minimum length of the array after performing any number of operations
Example 1:
Input: a = [2, 3, 3, 7, 3, 5], k = 20
Output: 3
Explanation:This is the list of operations that will give us the smallest array (1-based indexing):>Merge the elements at indices (1, 2), resulting array will be - [6, 3, 7, 3, 5] Merge the elements at indices (1, 2), resulting array will be - [18, 7, 3, 5] Merge the elements at indices (3, 4), resulting array will be - [18, 7, 15] Hence, the answer is 3.
Constraints:
:>/code>

Related Problems
Testcase
Result
Case 1
input:
output: