Minimum Time Difference | Easy Approach | Detailed | Leetcode 539 | codestorywithMIK

preview_player
Показать описание
This is the 109th Video of our Playlist "Array 1D/2D : Popular Interview Problems" by codestorywithMIK

In this video we will try to solve a good Array Problem with Bit Magic Property : Minimum Time Difference | Easy Approach | Detailed | Leetcode 539 | codestorywithMIK

I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Also, please note that my Github solution link below contains both C++ as well as JAVA code.

Problem Name : Minimum Time Difference | Easy Approach | Detailed | Leetcode 539 | codestorywithMIK
Company Tags : Palantir Technologies, META, Palantir

╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝

Summary :
The given approach to solving the problem of finding the minimum time difference between time points follows these steps:

Convert Time to Minutes: The input times are in HH:MM format. For each time string in the timePoints vector, the algorithm extracts the hours and minutes, converts them to integers, and then calculates the total minutes since midnight. These minute values are stored in a separate vector, minutes.

Sort the Minutes: The minutes vector is sorted to facilitate easy comparison of adjacent time points.

Find Minimum Difference: After sorting, the minimum time difference between consecutive times is calculated. A loop runs through the sorted list, comparing the difference between each pair of adjacent times.

Handle Circular Time: To account for the circular nature of the clock (e.g., the difference between 23:59 and 00:00), the algorithm also compares the difference between the last and the first time point across midnight.

Return the Result: The smallest difference found is returned as the result.

This approach ensures that the minimum time difference is efficiently found using sorting and simple comparisons. The time complexity is dominated by the sorting step, making it O(n log n).

✨ Timelines✨
00:00 - Introduction

#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #newyear2024
Рекомендации по теме
Комментарии
Автор

Hi MIK sir, there is slight mistake in 300 mins and 690mins as 690 mins will be 11:30am in the morning, not 11:30 pm of the night time. I'm attaching timestamp also 12:50.

Ankitkumar-fzkc
Автор

I completed 750 + question solved still I am waiting for your video for better understanding

footballcreativeeverywhere
Автор

24*60 minus 0th time index logic is the Paisa vasool for the complete video, big thanks to you

DurgaShiva
Автор

Universal GOAT of explanation apna MIK bhai💗💖

rickdutta
Автор

Hello Mik.
I just love your videos. And coming from a civil engineering background I just needed someone like you who can explain concepts....
I gathered all the software related knowledge online and in that you had a great contribution.
I got placed at the National stock exchange (NSE) as a software engineer. This was an on campus offer.
I just wanted to thank you so much.
And please keep doing the hard work.

sudhanshushekhar
Автор

Already done but here I am to find if any new approach is used in solving

Abhi-znup
Автор

I was able to solve it almost like 99 percent 😊 i felt happy, . excluding that reverse case

iams
Автор

Thanks for providing such great content sir. In your videos, your voice is so clear, which mic do you use for recording?

anubhavsharma
Автор

BUCKET SORT: total possible minutes are 1439, taking 00:00 as reference.

int timePoints) {
vector<bool> minuteMarks(1440, false);

for (auto &time: timePoints) {
int hoursToMinutes = ((time[0] - '0') * 10 + (time[1] - '0')) * 60;
int minutes = ((time[3] - '0') * 10 + (time[4] - '0'));

int totalMinutes = hoursToMinutes + minutes;

if (minuteMarks[totalMinutes]) {
return 0;
}
minuteMarks[totalMinutes] = true;
}

int firstMarkedMinute = -1, lastMarkedMinute = -1;
int minDifference = INT_MAX;
int currentMinute = 0;


while (firstMarkedMinute == -1) {
if (minuteMarks[currentMinute]) {
firstMarkedMinute = currentMinute;
lastMarkedMinute = currentMinute;
}
currentMinute++;
}

while (currentMinute < 1440) {
if (minuteMarks[currentMinute]) {
minDifference = min(minDifference, currentMinute - lastMarkedMinute);
lastMarkedMinute = currentMinute;
}
currentMinute++;
}

// Handle the circular case (last marked minute -> midnight -> first marked minute)
return min(minDifference, 1440 - lastMarkedMinute + firstMarkedMinute);
}
};

theOmKumar
Автор

Here to understand the corner case. You nailed it. Thanks a lot❤

FanIQQuiz
Автор

I successfully solved it using the Bucket Array approach about which you gave hints at the end. Thank you MIK ❤

kakshat
Автор

thanks done on my own with same approach but thanks for uploading

pranavJha
Автор

heyy Mik, With the help of your videoes, I am able to make till the HR round , Although got rejected .Thanks alot!!

vickyroy
Автор

Bhai, please make a detailed video on full implementation of a Bloom filter.

RahulSharma-jwes
Автор

Really you are amazing. I started seeing your videos since last month and i solved approx 220 questions on leetcode. Your explanation is amazing sir . One small request sir, it would be better if you could your ipad dry run notes part. ❤❤❤❤

Ankit-saw
Автор

Code Using Bucket Sort: class Solution {
public:
int arr)
{
int n=arr.size();
vector<int> minutes(1440, 0);
for(int i=0;i<n;i++)
{
int hour=stoi(arr[i].substr(0, 2));
int minute=stoi(arr[i].substr(3, 2));
int val=hour*60 + minute;
minutes[val]++;
}
int mini=INT_MAX, last=-1, first=-1;
for(int i=0;i<1440;i++)
{
if(minutes[i]==0) continue;
else if(minutes[i] > 1 ) return 0;
else if(last==-1)
{
first=i;
last=i;
}
else
{
mini=min(mini, i-last);
last=i;
}
}
mini=min(mini, 24*60-last + first);
return mini;
}
};

suyashjain
Автор

Sir it would be great if you solve longest special path

vikneshcs
Автор

Please make a video on Tarjans algorithm....

nikhil
Автор

bhaiya can you please suggest me series of question which i should follow to practise dsa

AryanChoudhary-wd
Автор

Sir please ek video Shortest Cycle in undirected par bana dijiye . Please Please

Gaurav-tk
join shbcf.ru