Created
April 6, 2017 19:54
-
-
Save tonholis/09b960c10f4c79d55dbe3ff213402fce to your computer and use it in GitHub Desktop.
HackerRank Booking.com - Customer Service Capacity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Problem: Determine how many people need to hire | |
Input specs: | |
- first line contains the current number of customer service executives | |
- second line contains a number of records in data set | |
- next linkes contains a pair of timestamps representing a start of call and end of call | |
Input demo: | |
1 | |
3 | |
1481222000 1481222020 | |
1481222000 1481222040 | |
1481222030 1481222035 | |
Expected result (number of additional customer service executives): | |
1 | |
*/ | |
static void Main(string[] args) | |
{ | |
var executives = int.Parse(Console.ReadLine()); | |
var n = int.Parse(Console.ReadLine()); | |
var calls = new List<Call>(); | |
var concurrent = 0; | |
for (var i = 0; i < n; i++) | |
{ | |
var timestamps = Console.ReadLine().Split(' '); | |
var call = new Call() | |
{ | |
Start = int.Parse(timestamps[0]), | |
End = int.Parse(timestamps[1]), | |
}; | |
calls.Add(call); | |
var otherCalls = calls.FindAll(x => x.Start >= call.Start || x.End <= call.End); //possible bug here | |
if (otherCalls.Count > concurrent) | |
concurrent = otherCalls.Count; | |
} | |
executives = concurrent - executives; | |
Console.WriteLine($"Additional executives: {executives}"); | |
Console.ReadKey(); | |
} | |
class Call | |
{ | |
public int Start { get; set; } | |
public int End { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment