Company: Freecharge
Difficulty: medium
Maximize Subarray Score You are given an array A of N integers, stored one element per row in the table elements , and an integer K , stored in the table config . For an integer X , let D(X) be the number of distinct prime factors of X ; it is pre-computed for every element in the column prime_factors . A score starts at 1 . You may perform the following operation at most K times : Choose a pair of indices (L, R) with 1 <= L <= R <= N that you have not chosen in any previous operation. In the subarray A[L..R] , find the dominant element : the element with the largest D(A[i]) . If several elements share that largest value, the one with the smallest index is dominant. Multiply score by the dominant element's value. Write an SQL query that returns the maximum possible value of score , modulo 1000000007 (10^9 + 7). Table: elements Column Type Description idx INTEGER 1-based position of the element; the values are exactly 1, 2, ..., N val INTEGER The element A[idx] prime_factors IN