TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

ShippingTime

Problem statement, definition, constraints, and public examples.

Problem Statement

You are shipping a box from sourceZipCode to destZipCode. Determine how long it will take for the package to arrive at its destination. You are given a String[], zones, which defines the locations of various zip codes. Each element of zones is a single space delimited list of five-digit integers. Element i (zero-indexed) of zones contains all the zip codes located in zone i. You are also given a int[], times, where the ith element (zero-indexed) is the number of days it takes for a package to travel between two zones whose difference is i. The difference between zone z1 and zone z2 is defined as the absolute value of z1 minus z2.

Definition

Class:
ShippingTime
Method:
getTime
Parameters:
int, int, String[], int[]
Returns:
int
Method signature:
int getTime(int sourceZipCode, int destZipCode, String[] zones, int[] times)
(be sure your method is public)

Constraints

  • sourceZipCode and destZipCode will each be between 10000 and 99999, inclusive.
  • zones will contain between 1 and 50 elements, inclusive.
  • Each element of zones will contain between 5 and 47 characters, inclusive.
  • Each element of zones will be a single space delimited list of one or more five-digit integers, with no leading or trailing spaces.
  • zones will contain no duplicate integers.
  • Both sourceZipCode and destZipCode will exist in zones.
  • times will contain the same number of elements as zones.
  • Each element of times will be between 1 and 7, inclusive.

Examples

  1. 48105
    79915
    {"94305", "79915 80201", "48105", "13122"}
    {2, 4, 5, 7}
    Returns: 4
    48105 is in element 2 of zones, so that means 48105 is located in zone 2. 79915 is located in zone 1. The difference in zones is 1, and element 1 of times is 4. Therefore, it will take 4 days for a package sent from 48105 to arrive at 79915.
  2. 94305
    94305
    {"94305 94309", "78000", "10001 03928"}
    {6, 7, 7}
    Returns: 6
    The source and destination zip codes are the same, so the difference in zones is 0. It will take 6 days for the package to arrive at its destination.
  3. 87654
    45678
    {"90000 12000 77777", "20000 45678 30000 87654"}
    {4, 3}
    Returns: 4
    The source and destination zip codes are different, but they are located in the same zone. Therefore, it will take 4 days.
  4. 10000
    99999
    {"10000 20000", "30000 40000", "50000 60000", "70000 80000", "90000 99999"}
    {1, 2, 3, 4, 5}
    Returns: 5
    The difference in zones between 10000 and 99999 is 4.
Back to all problems