2892. Minimizing Array After Replacing Pairs With Their Product
Given an integer array
nums
and an integerk
, you can perform the following operation on the array any number of times:
- Select two adjacent elements of the array like
x
andy
, 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 = 5
can become[1, 4, 3]
or[2, 2, 3]
, but can’t become[1, 2, 6]
).Return the minimum possible length of
nums
after any number of operations.
1 | class Solution { |