leetle

Daily challenge for 2026-04-10

465. Maximum Score from Distinct Pairs

Given an array of integers nums and an integer k, find the maximum sum of a contiguous subarray of length k such that the first and last elements of that subarray are different. If no such subarray exists, or if k < 2, return -1.

Example:
Input: nums = [5, 2, 1, 5, 8], k = 4
Output: 16

Explanation: The subarrays of length 4 are [5, 2, 1, 5] and [2, 1, 5, 8]. The first window is invalid because its first and last elements are both 5. The second window is valid because 2 != 8, and its sum is 16.

Run this challenge interactively in Python or JavaScript when the app loads.