2892. Minimizing Array After Replacing Pairs With Their Product
Given an integer array
numsand an integerk, you can perform the following operation on the array any number of times:
- Select two adjacent elements of the array like
xandy, such thatx * y <= k, and replace both of them with a single element with valuex * y(e.g. in one operation the array[1, 2, 2, 3]withk = 5can become[1, 4, 3]or[2, 2, 3], but can’t become[1, 2, 6]).Return the minimum possible length of
numsafter any number of operations.
1 | class Solution { |