Cover Listed Travel Days with Minimum Pass Cost

Quick Overview

Cover Listed Travel Days with Minimum Pass Cost. The strictly increasing array days lists travel days within one year.

Cover Listed Travel Days with Minimum Pass Cost

Company: Infosys

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem The strictly increasing array `days` lists travel days within one year. Passes lasting1,7,and30 consecutive days cost costs[0],costs[1],and costs[2] dollars respectively. A pass beginning on day d includes d through d+duration-1. Return the minimum total cost covering every listed travel day; unused covered days are allowed. ```cpp class Solution { public: int mincostTickets(vector<int>& days, vector<int>& costs); }; ``` ### Examples **Example 1:** ```text Input: days = [2,3,4,10], costs = [3,7,20] Output: 10 Explanation: A seven-day pass covering2 through8 costs7, and a single-day pass for10 costs3. Four single-day passes would cost12. ``` **Example 2:** ```text Input: days = [1,30,31], costs = [2,9,10] Output: 6 Explanation: Three single-day passes cost6, less than any useful longer-pass combination. ``` ### Constraints - `1 <= days.length <= 365`. - `1 <= days[i] <= 365`; days is strictly increasing. - costs has length3. - `1 <= costs[i] <= 1000`. ### Contract considerations Passes may cover days absent from the itinerary. All required days must be covered, even when widely separated. ```hint Read the boundary condition A pass covering the current travel day can replace a whole prefix of recent calendar-day obligations. ``` ### Boundary reminders Passes may cover days absent from the itinerary. All required days must be covered, even when widely separated.

Overview: Cover Listed Travel Days with Minimum Pass Cost. The strictly increasing array days lists travel days within one year.

Infosys logo
Infosys
Aug 30, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

The strictly increasing array days lists travel days within one year. Passes lasting1,7,and30 consecutive days cost costs[0],costs[1],and costs[2] dollars respectively. A pass beginning on day d includes d through d+duration-1. Return the minimum total cost covering every listed travel day; unused covered days are allowed.

class Solution {
public:
    int mincostTickets(vector<int>& days, vector<int>& costs);
};

Examples

Example 1:

Input: days = [2,3,4,10], costs = [3,7,20]
Output: 10
Explanation: A seven-day pass covering2 through8 costs7, and a single-day pass for10 costs3. Four single-day passes would cost12.

Example 2:

Input: days = [1,30,31], costs = [2,9,10]
Output: 6
Explanation: Three single-day passes cost6, less than any useful longer-pass combination.

Constraints

  • 1 <= days.length <= 365 .
  • 1 <= days[i] <= 365 ; days is strictly increasing.
  • costs has length3.
  • 1 <= costs[i] <= 1000 .

Contract considerations

Passes may cover days absent from the itinerary. All required days must be covered, even when widely separated.

Boundary reminders

Passes may cover days absent from the itinerary. All required days must be covered, even when widely separated.