Skip to content

Practice Maximize Y‑Sum by Picking a Triplet of Distinct X‑Values

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

Medium#3572
LeetCode Problem

Maximize Y‑Sum by Picking a Triplet of Distinct X‑Values

Problem Statement

Given equally long arrays x and y, choose three indices with pairwise distinct x-values. Return the maximum sum of their corresponding y-values, or -1 if fewer than three distinct x-values are available.

Source: Maximize Y‑Sum by Picking a Triplet of Distinct X‑Values on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
x = [1,2,1,3,2], y = [5,3,4,6,2]
Output
14

# Example 2

Input
x = [1,2,1,2], y = [4,5,6,7]
Output
-1

Constraints

n == x.length == y.length
3 <= n <= 10^5
1 <= x[i], y[i] <= 10^6

Related LeetCode Problems

Practice more problems similar to Maximize Y‑Sum by Picking a Triplet of Distinct X‑Values.

Review your practice with PhantomCodeAI

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