Task Scheduler | Easy Intuition | Using Heap | Leetcode 621 | codestorywithMIK

preview_player
Показать описание
This is the 14th Video of our Playlist "Heap (Priority Queue) : Popular Interview Problems".

In this video we will try to solve a very good and famous heap problem : Task Scheduler | Easy Intuition | Using Heap | Leetcode 621 | codestorywithMIK
NOTE - I will make a separate video for discussing another very good Greedy Approach for this problem.
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 : Task Scheduler | Easy Intuition | Using Heap | Leetcode 621 | codestorywithMIK
Company Tags  : META

Approach Summary : Simply use a greedy approach and get rid of tasks having max frequency so that we don't have to deal with them alone at last.Story frequency in max-heap. Start processing n+1 tasks(in descending order form max-heap) everytime and reduce the frequency of tasks by 1. If they are still remaining, push them back to heap.And keep calculating the time for processing the tasks. Once the heap is empty. Return the total time taken.
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝

 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
Рекомендации по теме
Комментарии
Автор

Thanks sir for the awesome explanation.
Here is the Java Code for the above explanation :
class Solution {
public int leastInterval(char[] tasks, int n) {
HashMap<Character, Integer> map = new HashMap<>();
for(char ch : tasks){
map.put(ch, map.getOrDefault(ch, 0) + 1);
}
PriorityQueue<Integer> pq = new
for(Map.Entry<Character, Integer> entry : map.entrySet()){
pq.add(entry.getValue());
}
int countInterval = 0;
while(!pq.isEmpty()){
ArrayList<Integer> temp = new ArrayList<>();
for(int i=1; i<=n+1; i++){
if(!pq.isEmpty()){
int freq = pq.peek();
pq.poll();
freq--;
temp.add(freq);
}
}
for(int val : temp){
if(val > 0){
pq.add(val);
}
}
if(!pq.isEmpty()){
countInterval += n+1;
}
else{
countInterval += temp.size();
}
}
return countInterval;
}
}

gouravdutta
Автор

You are just different from other YouTubers . Loved the explanation

FanIQQuiz
Автор

what a intuition thanks sir, never thought of that.

vedbhanushali
Автор

Awesome explanation sir, just i want to correct at the complexities part(t = tasks.size()) :
time: O(t) + O(26log26) + O(tlog26) = O(t)
space: O(n) [the worst case to store in temp vector]
thankyou

rakeshgarlapati
Автор

easiest explanation sir 👌. intuition gets into head .

abcdef-hce
Автор

Spent almost 5 hours on this question, and couldn't figure out solution for the edge cases.
But, this solution indeed makes a lot of sense! As always, love your explaination <3

akshaychavan
Автор

Mind blowing. Your videos exactly contain what i am always looking for

DevOpskagyaan
Автор

I am thinking about one more approach where a sort the frequency and use the formula if n<(length-i) then t+= arr[i]*(length-i) else t+= arr[i]*(length-i) + (n-i)*arr[i] by traversing the loop and decreasing prefix sum by adding arr[i] whichever next element I will traverse is it correct

inderlalchandani
Автор

As always bhaiyaa Amazing Explanation ✨

ManishKumar-kbwx
Автор

Good explanation as always. Please upload the gfg question also maximum paths in tree

lostcyrus
Автор

Thanks a lot bhaiya ❤❤ & congrats for 50k subs 🥳🥳

gauravbanerjee
Автор

greeedy wala method bhi btao bhaiya, wo bhi seekhna h

abhisheksinghdangi
Автор

Good Explanation bhai also provide greedy 😄

ajinkyakhete
Автор

could u upload soln of gfg potd, similar type of problem came in my OT Thoughspot but i was unable to solve. problem name is : possible paths in a tree

mohdalizilani
Автор

hlw, can you please lemme know when there is no element to store we store an idle time in the vector/array list, where is exactly the logic used in the code to store that? I cant get that thing

TasniaTahsinNujhat
visit shbcf.ru