count
to 0
to keep track of the number of elements that cannot be combined.last
to store the last element that was either added to the count or combined with its previous element.nums
.
a. If the current element is 0
, return 1
immediately.
b. If last
is not None
and the product of last
and the current element is less than or equal to k
, update last
to be the product of last
and the current element.
c. If the product is greater than k
, increment count
by 1
and update last
to be the current element.count
as the minimum possible length of the array after the operations.