Created
May 23, 2021 21:09
-
-
Save Ezeji/a961dee970ab7b9778216a9d5e15a078 to your computer and use it in GitHub Desktop.
This algorithm finds the minimum time difference between any two times in an array.
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 | |
{ | |
private static List<string> MinutesArray { get; set; } = new List<string>(); | |
static void Main(string[] args) | |
{ | |
string[] timeArray = { "16:15", "16:00", "12:20" }; | |
GetMinutesFromTimeArrayIntoMinutesArray(timeArray); | |
var result = MinimiumTimeDifference(MinutesArray); | |
Console.WriteLine("Result:" + " " + result); | |
} | |
public static void GetMinutesFromTimeArrayIntoMinutesArray(string[] timeArray) | |
{ | |
if (timeArray == null) { } | |
else | |
{ | |
string timeArrayElement; | |
for (int i = 0; i < timeArray.Length; i++) | |
{ | |
timeArrayElement = timeArray[i]; | |
MinutesArray.Add(timeArrayElement.Substring(3)); | |
} | |
} | |
} | |
public static string MinimiumTimeDifference(List<string> minutesArray) | |
{ | |
if (minutesArray == null) { return null; } | |
else | |
{ | |
var minutesArrayMinimum = minutesArray.Min(); | |
MinutesArray.Remove(minutesArrayMinimum); | |
MinutesArray.Sort(); | |
return MinutesArray[0] + " " + "minutes"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment