Connection Status:
Competition Arena > BusyHours
SRM 59 · 2002-01-23 · by kyky · Simple Search, Iteration, String Parsing
Class Name: BusyHours
Return Type: int[]
Method Name: minMaxLoad
Arg Types: (vector<string>)
Problem Statement

Problem Statement

An airline freight sorting hub is serviced by several planes. Given each plane's flight schedule, determine the busiest hour of the day when the number of planes at the hub is the highest, and the least loaded hour of the day, when the number of planes at the hub is the lowest. In cases when multiple such hours exist, pick the earliest ones.

Each element of schedule has 24 characters, and represents an hour-by-hour schedule of one plane. Each position in the string corresponds to an hour of the day; '1' (one) and '0' (zero) are the only characters allowed in the strings. When position X in the string contains '1', the plane is at the hub at the hour X; when the character is '0', the plane is not at the hub at that hour.

Constraints

  • schedule contains between 1 and 50 elements, inclusive
  • Elements of schedule are exactly 24 characters in length
  • Elements of schedule do not contain characters other than '0' (zero) and '1' (one).
Examples
0)
{"010101010101010101010101", "101010101010101010101010"}
Returns: { 0,  0 }
1)
{"010101010101010101010101", "010101010101010101010101"}
Returns: { 0,  1 }
2)
{"110000000000001100000001", "110000000001111100000000", "000111110000000111100000"}
Returns: { 2,  15 }
3)
{"110000000000001100000001", "110000000001111100000000", "000111110000000111100000", "000000000011110000000111", "111111100001111100000111", "100111110000000111100100"}
Returns: { 8,  15 }
4)
{"110000000000001100000001", "110000000001111100000000", "000111110000000111100000", "000000000011110000000111", "111111100001111100000111", "100111110000000111100100", "110000000000001100000001", "110000000001111100000000", "000111110000000111100000", "000000001111110000000111", "111111100001111100000111", "100111110000000111100100"}
Returns: { 19,  15 }
42)
{ "110000000000001100000001",
  "110000000001111100000000",
  "000111110000000111100000"}
Returns: { 2,  15 }

2 is the earliest hour when there are no planes at the hub, and 15 is the busiest hour, when all three planes are at the hub.

43)
{ "010101010101010101010101",
  "101010101010101010101010"}
Returns: { 0,  0 }

All hours are equally loaded, and 0 is the earliest of them.

Submissions are judged against all 45 archived test cases, of which 7 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class BusyHours with a public method vector<int> minMaxLoad(vector<string> schedule) · 45 test cases · 2 s / 256 MB per case

Submitting as anonymous