Skip to content

Practice Apply Operations on Array to Maximize Sum of Squares

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

Hard#2897
LeetCode Problem

Apply Operations on Array to Maximize Sum of Squares

Problem Statement

In one operation, choose different indices i and j and simultaneously replace their values by nums[i] AND nums[j] and nums[i] OR nums[j], using the two old values. After any number of operations, choose k entries. Return the largest possible sum of their squares, modulo 10^9 + 7.

Source: Apply Operations on Array to Maximize Sum of Squares on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [2,6,5,8], k = 2
Output
261

# Example 2

Input
nums = [4,5,4,7], k = 3
Output
90

Constraints

1 <= k <= nums.length <= 10^5
1 <= nums[i] <= 10^9

Related LeetCode Problems

Practice more problems similar to Apply Operations on Array to Maximize Sum of Squares.

Review your practice with PhantomCodeAI

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