LeetCode 3496: Maximize Score After Pair Deletions Solution

Master LeetCode problem 3496 (Maximize Score After Pair Deletions), a medium challenge, with our optimized solutions in Java, C++, and Python. Explore detailed explanations, test your code in our interactive editor, and prepare for coding interviews.

3496. Maximize Score After Pair Deletions

Problem Explanation

Explanation:

Given an array of integers nums, we want to maximize the score after deleting pairs (i, j) where i < j such that the score is the sum of nums[i] * nums[j].

To maximize the score, we can sort the array and pair the largest numbers with the smallest numbers. This way, we can maximize the product of the pairs. We can then calculate the score by iterating through the array and summing the product of pairs. :

Solution Code

class Solution {
    public int maxScore(int[] nums) {
        Arrays.sort(nums);
        int n = nums.length;
        int score = 0;
        
        for (int i = 0; i < n / 2; i++) {
            score += nums[i] * nums[n - 1 - i];
        }
        
        return score;
    }
}

Try It Yourself

Loading code editor...

Related LeetCode Problems

Frequently Asked Questions

How to solve LeetCode 3496 (Maximize Score After Pair Deletions)?

This page provides optimized solutions for LeetCode problem 3496 (Maximize Score After Pair Deletions) in Java, C++, and Python, along with a detailed explanation and an interactive code editor to test your code.

What is the time complexity of LeetCode 3496 (Maximize Score After Pair Deletions)?

The time complexity for LeetCode 3496 (Maximize Score After Pair Deletions) varies by solution. Check the detailed explanation section for specific complexities in Java, C++, and Python implementations.

Can I run code for LeetCode 3496 on DevExCode?

Yes, DevExCode provides an interactive code editor where you can write, test, and run your code for LeetCode 3496 in Java, C++, or Python.

Back to LeetCode Solutions