LeetCode 539. Minimum Time Difference (Solution Explained)

preview_player
Показать описание


Preparing For Your Coding Interviews? Use These Resources
————————————————————

Other Social Media
----------------------------------------------

Show Support
------------------------------------------------------------------------------

#coding #programming #softwareengineering
Рекомендации по теме
Комментарии
Автор

very nice solution and explanation, but essentially, you can remove line 30. And on line 23 you can replace `1440 - i + prev_time_seen` with `1440 - i + first_time_seen`. Again great solution!

ManankValand
Автор

you explained it pretty well, didnt have any hardtime getting this.

MrThepratik
Автор

Please mention about counting sort. Essentially the concept is the same.

xxism
Автор

What is the difference between bucket sort(this approach) and count sort?

diptilulla
Автор

Superrr ...explanation thanxs for we want you too speak some slowly soo that we can understand more precisely

Krishna
Автор

If numbers in limited range, can sort (with 0s at some indices) using such method

vk
Автор

how come did you assign null to int like this one integer first_time_seen = null;

seanelias
Автор

I think last line (30) should be minimum_difference = Math.min(minimum_difference, 1440 - pre_time_seen + first_time_seen)
as prev_time_seen always be greater than first_time_seen and the difference between them will be negative.

HarshalDhumal
Автор

class Solution {
public int findMinDifference(List < String > times) {
boolean[] time_zones = new boolean[1440];
int min = Integer.MAX_VALUE;
for(String str : times){
String[] timeData = str.split(":");
int minutes = Integer.parseInt(timeData[0]) * 60;
minutes +=
if(time_zones[minutes]){
return 0;
}
time_zones[minutes] = true;
}
int curr = -1;
int prev = -1;
int first = -1;
for(int i = 0; i < 1440; i++){
if(time_zones[i]){
if(prev == -1){
first = i;
prev = i;
}
else{
curr = i;
min = Math.min(min, curr - prev);
prev = curr;
}
}
}
min = Math.min(min, ((1440 - curr) + first));
return min;
}
}

sarthakdalabehera
Автор

I know nobody will see this but still why nobody used an array of size 1440 initialized to 0 and then making values one when we add does booolean array (bitset) has any extra utility ?
[thankyou for the soln]

avishkarghadge
Автор

First-time_seen and last_time_seen is pretty confusing to me :(

jax
Автор

Thank you! This is pretty great explanation!

lingyunsu
Автор

Would this work?
Append 2 boolean array to each other
Therefore resultant will be of size(1440+1440) . Now calculate min difference btw the consecutive boolean true values

milanapegaonkar
Автор

why are there so few comments on this video?

samuelgunter
Автор

Use dark mode please. You hurt my eyes

icet