Created
July 12, 2021 12:34
-
-
Save schauhan232/e89d7859d576b1a519bc9b8467d47b1a to your computer and use it in GitHub Desktop.
Minimum Number of platform needed
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
class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
var arrival = new int[] { 900, 940, 950, 1100, 1500, 1800 }; | |
var departure = new int[] { 910, 1200, 1120, 1130, 1900, 2000 }; | |
Array.Sort(arrival); | |
Array.Sort(departure); | |
var current = 0; | |
var next = 1; | |
var platformNeededd = 0; | |
var maxPlatformNeeded = 1; | |
while (current <= arrival.Length - 1 && next <= arrival.Length - 1) | |
{ | |
if (arrival[current] < departure[next]) | |
{ | |
current++; | |
platformNeededd++; | |
if (platformNeededd > maxPlatformNeeded) | |
maxPlatformNeeded = platformNeededd; | |
} | |
else | |
{ | |
next++; | |
platformNeededd--; | |
} | |
} | |
Console.WriteLine($"Maximum Platform: {platformNeededd}"); | |
Console.Read(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment