Dsa
Two Pointers
Medium
Wine Pairing
You have a list of wines where each wine has a rating. Your goal is to maximize the average rating of wine pairs. Each wine can be paired only once, and you need to return the maximum average rating of any formed pairs. If there's an odd number of wines, the last wine will be left unpaired.
Input:
- The first line contains a single integer N (1 ≤ N ≤ 1000), the number of wines.
- The second line contains N space-separated integers representing the ratings of the wines.
Output:
- Print the maximum average rating of the pairs, formatted to two decimal places.
Example:
Input:
5
3 6 2 8 4
Output:
6.00
Key concepts
two_pointersgreedy_algorithms
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