← All problemsSign in

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

LeetCodeArrayHash TableGreedySortingHeap (Priority Queue)Open on judge ↗

You are given two integer arrays x and y, each of length n. You must choose three distinct indices i, j, and k such that: - x[i] != x[j] - x[j] != x[k] - x[k] != x[i] Your goal is to maximize the value of y[i] + y[j] + y[k] under these conditions. Return the maximum possible sum that can be obtained by choosing such a triplet of indices. If no such triplet exists, return -1. Example 1: In

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start