Tap here to switch tabs
Problem
Submissions

Problem: Maximum Vacation Days

med
30 min
Try to solve the Maximum Vacation Days problem.

Statement

You are planning your vacation across nn cities labeled from 00 to n−1n - 1, over a total duration of kk weeks.

You are given a 22D integer array flights of size nimesnn imes n, where flights[i][j] = 1 indicates that a direct flight exists from city i to city j, and flights[i][j] = 0 indicates no direct flight exists. You are also given a 22D integer array days of size nimeskn imes k, where days[i][j] represents the maximum number of vacation days you can spend in city i during week j.

At the beginning of week 00, you start in city 00. On Monday of each week, you can either take a flight from your current city to another city if a direct flight exists, or remain in the current city. Flights take no significant time, and you can immediately enjoy vacation days in the chosen city for that week.

Return the maximum number of vacation days you can collect across all kk weeks.

Constraints:

  • n == flights.length

  • n == flights[i].length

  • n == days.length

  • k == days[i].length

  • 1≤n,k≤1001 \leq n, k \leq 100

  • flights[i][j] is either 00 or 11.

  • 0≤0 \leq days[i][j] ≤7\leq 7

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Vacation Days

med
30 min
Try to solve the Maximum Vacation Days problem.

Statement

You are planning your vacation across nn cities labeled from 00 to n−1n - 1, over a total duration of kk weeks.

You are given a 22D integer array flights of size nimesnn imes n, where flights[i][j] = 1 indicates that a direct flight exists from city i to city j, and flights[i][j] = 0 indicates no direct flight exists. You are also given a 22D integer array days of size nimeskn imes k, where days[i][j] represents the maximum number of vacation days you can spend in city i during week j.

At the beginning of week 00, you start in city 00. On Monday of each week, you can either take a flight from your current city to another city if a direct flight exists, or remain in the current city. Flights take no significant time, and you can immediately enjoy vacation days in the chosen city for that week.

Return the maximum number of vacation days you can collect across all kk weeks.

Constraints:

  • n == flights.length

  • n == flights[i].length

  • n == days.length

  • k == days[i].length

  • 1≤n,k≤1001 \leq n, k \leq 100

  • flights[i][j] is either 00 or 11.

  • 0≤0 \leq days[i][j] ≤7\leq 7