474. Road Journey Times
Road Journey Times

A travel app lists the total journey times, in minutes, to several destinations using different road routes.

Each row represents one route. Each column represents the same destination across all routes. Times never decrease from left to right within a row or from top to bottom within a column. Equal times are allowed.

Return true if any listed journey takes exactly requiredTime minutes. Otherwise, return false.

Method Signature

boolean hasJourneyTime(List<String> travelTimes, int requiredTime)
  • travelTimes: one string per row, containing comma-separated journey times. For example, "14,27,43" represents three destinations on one route.
  • requiredTime: the exact journey time to find, in minutes.

Constraints

  • travelTimes contains between 1 and 300 strings.
  • Each string contains between 1 and 300 integers.
  • Every string contains the same number of integers.
  • Each journey time and requiredTime is between 1 and 1,000,000,000, inclusive.

Examples

Example 1

hasJourneyTime(travelTimes = List.of("14,27,43,68", "20,34,51,79", "29,42,63,96"), requiredTime = 51)

Output: true

The second route reaches the third destination in exactly 51 minutes.

Example 2

hasJourneyTime(travelTimes = List.of("9,23,38", "17,31,46"), requiredTime = 29)

Output: false

No listed journey takes exactly 29 minutes.

Example 3

hasJourneyTime(travelTimes = List.of("18,18,33", "18,27,45"), requiredTime = 18)

Output: true

Several journeys take 18 minutes. Any one of them is enough.



Please use Laptop/Desktop or any other large screen to add/edit code.