Company: Freecharge
Difficulty: medium
Problem Description You are tasked with finding the maximum possible score by analyzing the "dominant elements" of all possible subarrays within a given dataset. You are provided with two tables: elements , which represents an array of numbers, and config , which provides a limit k . For any pair of indices (L, R) where 1 ≤ L ≤ R ≤ N , a "subarray" is defined as all elements with an idx between L and R (inclusive). For each possible subarray, you must identify its dominant element using the following rules: The dominant element is the element with the highest prime_factors (the number of distinct prime factors of its value) within the subarray. If there is a tie, the element with the smaller idx is chosen. Consider a multiset (a collection that allows duplicates) containing the val of the dominant element for every possible subarray. To maximize your score, you must select the k largest values from this collection. If the total number of subarrays is less than k , select all o