Question bank › Two Pointers
Dsa Two Pointers Medium

Potion Mixing

You are given a list of integers representing the volumes of different potion ingredients. Your task is to find the maximum total volume of two ingredients that can be mixed together while ensuring that the mixed volume does not exceed a given threshold. You need to return the maximum sum of any two distinct ingredients that satisfies the constraint. Input: - The first line contains a single integer N (1 ≤ N ≤ 1000), the number of ingredients. - The second line contains N space-separated integers denoting the volumes of the ingredients. - The third line contains a single integer T (1 ≤ T ≤ 10000), the threshold volume. Output: - Print the maximum total volume of any two distinct ingredients, or -1 if no such pair exists. Example: Input: 5 10 15 3 7 8 20 Output: 18

Key concepts

two_pointersarray_manipulation

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.