Dsa
Greedy
Medium
Optimal Ticket Purchase Strategy
You need to buy tickets for an event with varying prices over different days. The price changes daily, and you can only buy tickets for a maximum of two days. Your goal is to minimize your spending while ensuring that you can attend the event for two consecutive days.
Input format:
- The first line contains an integer d (2 ≤ d ≤ 100), the number of days.
- The second line contains d integers, representing the ticket prices for each day.
Output format:
- Print a single integer, the minimum total cost of tickets for two consecutive days.
Example:
Input:
5
50 40 60 30 20
Output:
50
Key concepts
greedyintervalsarray
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