Minimum Time Difference

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.
I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.
Given a list of 24-hour clock time points in "HH:MM" format, return the minimum minutes difference between any two time-points in the list.
LeetCode Problem - 539
class Solution {
public int findMinDifference(List<String> timePoints) {
int answer = Integer.MAX_VALUE; // Variable to store the minimum time difference
List<Integer> list = new ArrayList<>(); // List to store the time in minutes
// Convert each time point (in "HH:MM" format) to minutes
for (String timePoint : timePoints) {
String[] stamp = timePoint.split(":"); // Split the time into hours and minutes
int hh = Integer.parseInt(stamp[0]); // Parse the hours part
int mm = Integer.parseInt(stamp[1]); // Parse the minutes part
list.add(hh * 60 + mm); // Convert time into total minutes and add to the list
}
// Sort the list to arrange the time points in ascending order
Collections.sort(list);
// Find the minimum difference between consecutive time points
for (int i = 0; i < list.size() - 1; i++) {
int diff = list.get(i + 1) - list.get(i); // Difference between consecutive times
answer = Math.min(answer, diff); // Update the answer with the minimum difference found
}
// Handle the circular case where the time wraps around from 23:59 to 00:00
int circularDiff = 1440 - (list.get(list.size() - 1) - list.get(0)); // Difference between the last and first time in a circular manner
answer = Math.min(answer, circularDiff); // Update the answer with the circular difference if it's smaller
return answer; // Return the minimum time difference found
}
}




