Company: Texas

Difficulty: medium

Problem Statement

Compressing an Array You are given `n` positive integers and a positive integer `k`. In one operation, choose two adjacent elements whose product is at most `k`, remove them, and insert their product in their place. Perform any number of operations and output the smallest possible final array length. Input Format The first line contains `n` and `k`. The second line contains `n` positive integers. Output Format Print the minimum final length. Constraints `1 <= n <= 200000`, `1 <= a[i], k <= 10^9`. Products are compared using 64-bit integers. Example Input: `5 20` then `2 3 3 7 3` Output: `3` Notes The merge sequence can form `6, 3, 7, 3`, then `18, 7, 3`, then `18, 7, 15`.

More Texas OA questionsInterview experiences