MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / Solution

Class Solution

minimumTimeDifference.java:1–31  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class Solution {
2 public int findMinDifference(List<String> timePoints) {
3 boolean mins[] = new boolean[1440];
4 for(String time : timePoints){
5 int h = Integer.parseInt(time.substring(0,2));
6 int m = Integer.parseInt(time.substring(3,5));
7 int minutes = h*60 + m;
8 if(mins[minutes]) return 0;
9 mins[minutes] = true;
10 }
11 int prev=-1;
12 int firstVal=-1;
13 int minDiff = Integer.MAX_VALUE;
14 for(int cur = 0;cur < 1440; cur++){
15 if(mins[cur]){
16 if(prev==-1){
17 firstVal = cur;
18 prev = cur;
19 }else{
20 minDiff = Math.min(minDiff,cur-prev);
21 prev = cur;
22 }
23 }
24 }
25 if(prev!=-1){
26 minDiff = Math.min(minDiff,1440 + firstVal - prev);
27 }
28 return minDiff;
29
30 }
31}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected