Statistics

Problem Statement for "Itinerary"

Problem Statement

PROBLEM STATEMENT
A trip itinerary consists of multiple flight segments. For each flight, the
itinerary defines its endpoints, and the local times of the flight's arrival
and departure. Given an itinerary and a list of time zones, calculate the total
length of all flights during the trip.

DEFINITION
Class name: Itinerary
Method name: flightTime
Parameters: String[], String[]
Return type: int
Method signature (be sure your method is public): int flightTime (String[]
flights, String[] zones);

Each element of flights is formatted as follows (here and below quotation marks
'"' as well as the '>' and '<' characters are for clarity only):
"<origin> <departure time> <destination> <arrival time>"
There will be exactly one space between components of the string. The origin
and the destination are three-character airport codes. Arrival and departure
time have the following format:
"HH:MM"
where HH is the hour and MM is the minute of the arrival or departure,
expressed as "military time" (24-hour clock).  Additionally, the arrival time
may have a "+1", "+2" or "-1" date correction code.
For example, "SFO 15:45 CDG 07:35+1" describes a flight leaving SFO at 3:45 PM,
and arriving at CDG at 7:35 AM the next day. Here is another example: "LHR
00:30 JFK 23:30-1". This flight leaves LHR at 12:30 AM, and arrives at JFK at
11:30 PM on the earlier day. Date correction codes are optional: they are used
only when the departure and the arrival dates are different. Note that there is
no space between the arrival time and the date correction code.

Each element of zones is formatted as follows:
"<airport code> <sign>HH:MM"
The airport code is a three-letter code; the offset consists of an optional "+"
or "-" sign, followed by HH:MM, representing the hour and the minute difference
between the Greenwich Mean Time and the time at the airport. When the sign is
missing, the difference is positive. There will be exactly one space between
the airport code and the offset. For example, "JFK -05:00" specifies that JFK
is in the time zone which is five hours behind the Greenwich Mean Time.

Your method should return the total lengths, in minutes, of all flights.

TopCoder will ensure the validity of the inputs.  Inputs are valid if all of
the following criteria are met:
- The flights has between 1 and 25 entries, inclusive,
- The zones has between 1 and 50 entries, inclusive,
- Entries of flights are formatted as described above,
- Entries of zones are formatted as described above,
- Time offset of a zone is in the range from -12:00 to +12:00, inclusive,
- Airport codes contain exactly three letters ('A'-'Z', 'a'-'z'; possibly in
mixed case, which should not be ignored - for example, "SFO" is not the same as
"sFo"),
- Each airport listed as an origin or a destination in the flights has a
corresponding entry in the zones,
- No airport is listed more than once in the zones,
- Each flight takes at least 20 minutes,
- No flight takes longer than 23 hours.

NOTES
- If a flight's departure time is earlier than the arrival of the preceding
flight, this means that the departure happens on the next day.
- A flight may not necessarily originate at the airport where the prior flight
has arrived.

EXAMPLES
1. If flights={"JFK 00:00 EWR 00:20","LGA 01:00 SFO 04:00"}, and zones={"JFK
-05:00","EWR -05:00","LGA -05:00","SFO -08:00"}, your method should return 380:
the first flight takes 20 minutes, then there is a 40-minute wait, and then
there is a 6-hour (360 minutes) flight. Therefore, the passenger spends a total
of 20+360 = 380 minutes in flight.
2. If flights={"BOM 12:00 HYD 13:40", "EWR 10:10 DFW 13:50", "SFO 15:00 SEL
13:00+1"}, and zones={"BOM +05:30", "HYD +05:30", "EWR -05:00", "DFW -06:00",
"SFO -08:00", "SEL +09:00"}, your method should return 680.
3. If flights={"LHR 00:30 JFK 23:30-1", "LHR 00:45 EWR 23:27-1"}, zones={"LHR
00:00", "JFK -05:00", "EWR -05:00"}, your method should return 462.

Definition

Class:
Itinerary
Method:
flightTime
Parameters:
String[], String[]
Returns:
int
Method signature:
int flightTime(String[] param0, String[] param1)
(be sure your method is public)

Constraints

    Examples


      This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
      This problem was used for: