Skip to content

Practice Apply Operations to Maximize Score

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#2818
LeetCode Problem

Apply Operations to Maximize Score

Problem Statement

Begin with score 1. In each of at most k operations, choose a nonempty nums subarray whose index interval has not been chosen before. Within it, select the value having the most distinct prime factors, breaking ties by earliest index, and multiply the score by that value. Return the greatest attainable score modulo 10^9 + 7.

Source: Apply Operations to Maximize Score on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [8,3,9,3,8], k = 2
Output
81

# Example 2

Input
nums = [19,12,14,6,10,18], k = 3
Output
4788

Constraints

1 <= nums.length == n <= 10^5
1 <= nums[i] <= 10^5
1 <= k <= min(n * (n + 1) / 2, 10^9)

Related LeetCode Problems

Practice more problems similar to Apply Operations to Maximize Score.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.