Skyline Problem

  Рет қаралды 194,258

Tushar Roy - Coding Made Simple

Tushar Roy - Coding Made Simple

Күн бұрын

Пікірлер
@ChirangiviBhat-i2g
@ChirangiviBhat-i2g Жыл бұрын
I understood the effort you put in the video when you said in 5:57: "At point thhwu before the shthhart of the building, the maximum value was thhfree"
@usrenaem
@usrenaem 2 жыл бұрын
When I saw this task for the first time I have absolutely no idea how to solve it, no technics/algorithms I knew including priority queue looked like a possible solution. Thanks a lot for that clear explanation!
@hunarjain4867
@hunarjain4867 4 жыл бұрын
I am here because of LeetCode Daily Challenge and Tushar never fails to deliver..😄🙌🏿🙌🏿🙌🏿
@shrn
@shrn 10 ай бұрын
I've looked at 5-6 tutorials but did not understand what to do, but after watching this video, it became very simple
@a1988ditya
@a1988ditya 5 жыл бұрын
First of all , would like to say - top class videos and explanation. Really helpful thank u. 1) You dont have to delete items and PQ does not support Log(n) deletes 2) i would keep a heap of objects rather than height alone , as it takes care of case where multiple buildings have same height. Coming to delete , you can ignore deletion - when you do pop_heap you can figure out if that building is stale or not by checking if its x end position is less that the current x position. If its stale just pop it out 3) This is just a line sweep algo application problem
@ranga400
@ranga400 3 жыл бұрын
Just Brilliant. Appreciate your patience in going through the code line by line and using the visual to make things clear. Hats off
@123chen9
@123chen9 3 жыл бұрын
I have to say this is the simplest explaination I have ever seen! Thank you
@ArijitDebYoutubeChannel
@ArijitDebYoutubeChannel 4 жыл бұрын
Great explanation! Also, using TreeMap instead of PriorityQueue to improve the remove(Object) operation time complexity from O(N) to O(logN) is a brilliant idea.
@SunilPatel-sf5ng
@SunilPatel-sf5ng 3 жыл бұрын
Thank you so much sir. I've a got a job because of you. Please continue to deliver awesome algorithms and techniques.
@casperauto
@casperauto 6 жыл бұрын
Cannot be more clear! It was a lot of work to make this. Thank you.
@pradeepbalasundaram
@pradeepbalasundaram 4 жыл бұрын
Hi Tushar, great videos. Learned a lot. For your future videos I was hoping if you could talk a few minutes about how to develop an intuition in to solving problems. For example, at first the skyline problems seems almost insurmountable even as I think about it in the leisure of my living room. In a pressure cooker situation that is the interview, all my prefrontal functions seem to come to a standstill and there is no hope of even remotely coming close to an approach , let alone write the code for it. It would be of great if you can break down the process of developing an intuition for problems like these. Like for example. How do I solve it by brute force, is there a key insight that can help me solve it better. Why some approaches will work for a certain type of problem and why others wont. How to quickly come up with a subset of approaches that might work. How not to get overwhelmed by the question. For example, the skyline problem can be solved by a heap, or by divide and conquer. Now, how do I come up with either of these approches as if I had never seen this problem before ? - Teach a man to fish and he will eat for a lifetime
@Bswarup
@Bswarup Жыл бұрын
I totally agree...We can start with Brute force approach first and then can come to optimized sol..
@Tejas8272
@Tejas8272 Жыл бұрын
Finally able to solve with your explanation after almost 2 days searching debugging others solution /code Thank you👍🏻
@piyushbansal8004
@piyushbansal8004 4 жыл бұрын
Great work Tushar...You made it very clear especially the edge cases. For those who write in c++ the compare function for sorting the buildings is bool operator()(bb a, bb b) { if (a.x != b.x) { return a.x < b.x; } else if (a.isStart and b.isStart) { return a.y > b.y; //building with larger height } else if (!a.isStart and !b.isStart) { return a.y < b.y; //building with smaller height } else { return a.isStart; //if end and another start we will consider start building first } }
@snehalbedmutha1895
@snehalbedmutha1895 3 жыл бұрын
Thank you for this excellent explanation. I wrote your code in Python and I'm getting TLE for one test case (69/70 passed).
@sidharthbihary2475
@sidharthbihary2475 5 жыл бұрын
beautifully explained. thanks Tushar. the best part of problem solving is you discuss the idea of the solution before jumping directly into the algorithm part.
@larry1285
@larry1285 5 жыл бұрын
nice explanation, the only one I can understand among the tutorials I have found so far
@larry1285
@larry1285 5 жыл бұрын
I cannot find a built-in method to delete a specific item from priority queue in python. Could you tell me what should I do to solve the problem using the method taught in the video? Thank you so much
@larry1285
@larry1285 5 жыл бұрын
since your python version does not pass the test 35 either, I know you use dict and use max(queue.keys()) to get the maximum
@sungbokang1492
@sungbokang1492 5 жыл бұрын
The easiest approach I've seen. Thanks!
@Jeremy0Sea
@Jeremy0Sea 8 жыл бұрын
This is the best explanation on skyline problem I have ever seen so far. Great Job Tushar!
@syafzal273
@syafzal273 6 жыл бұрын
Great video. I like that you went over the algorithm and why it works unlike some of the DP videos where the answer is explained but now how it was arrived at​. Also, love that you have python code!
@Young10489
@Young10489 3 жыл бұрын
Tushar has become my favorite Indian .
@kyryloreznykov4959
@kyryloreznykov4959 8 жыл бұрын
The best channel about algorithms on youtube! Thank you.
@raghav28489
@raghav28489 5 жыл бұрын
nope, many of his videos are simply mugged up intuition-less explanations
@BackToBackSWE
@BackToBackSWE 5 жыл бұрын
You are the og whiteboard youtuber
@dargy2368
@dargy2368 5 жыл бұрын
You literally saved my life thank you so much. (I understand the homework thanks to you 4 hour before due date).
@saurabhdsawant
@saurabhdsawant 8 жыл бұрын
Very useful! Great efforts. Appreciate it Tushar Roy. Thank you for uploading. The code part helps a lot also would be perfect if we can just discuss naive approaches for the problems at the start. Thanks again.
@josebenardi1554
@josebenardi1554 7 жыл бұрын
Your videos were really helpful to me during this last semester, thank you for making this available.
@deathbombs
@deathbombs 2 жыл бұрын
The sorting algorithm for buildingPoints class is key here for finding start, end, and skyline height: (this.isStart ? -this.height : this.height - o.isStart ? -o.height : o.height) if same x, sort the start points by height, ignore the end points if not same x, sort by x
@cyf6412
@cyf6412 7 жыл бұрын
Tushar's youtube video is really efficient to learn. Thanks!
@rahul38474
@rahul38474 3 жыл бұрын
I got this question in a final round for an internship and even though I barely understood the question I still somehow managed to come up with this solution, I didn’t even understand the answer I was giving the interviewer.
@chenhaofeng4842
@chenhaofeng4842 2 жыл бұрын
The best video for skyline problem
@zhangbrian102
@zhangbrian102 2 жыл бұрын
Cannot thank more. Do appreciate your great explanation!
@ignaciogomez1816
@ignaciogomez1816 8 жыл бұрын
Pretty simple! I saw almost all your videos and I have to say that you made a great job. It would be helpful if you can share your interview experiences too Congratulations!!!
@hannanathar3627
@hannanathar3627 8 ай бұрын
00:02 Merge overlapping buildings to form skyline view 02:35 Algorithm for finding skyline points 04:53 Tracking building heights to determine skyline changes. 07:11 Process the input points and prioritize based on start and end values 09:39 Understanding edge cases in the Skyline Problem 12:00 Examining time complexity of the problem. 14:06 Ordering rules for buildings based on heights 16:14 Updating building heights and recording the maximum height 18:03 Tracking and updating the current max height 19:58 Explanation of adding and deleting building points based on conditions 21:53 Deleting a single count from map affects height calculation
@briankarcher8338
@briankarcher8338 2 жыл бұрын
This is a crazy awesome explanation of a really hard problem. Hats off to you. You should get back to the KZbin game :)
@gauravruhela007
@gauravruhela007 4 жыл бұрын
Tushar bhai....Tussi great ho!
@benpurcell591
@benpurcell591 4 ай бұрын
3 mins in , very clear, great explanation
@biboswanroy6699
@biboswanroy6699 4 жыл бұрын
There is also a divide and conquer approach. This approach is nice. But in cpp I had to use multimap and create a priority queue according to the requirement for removing any node. In an interview it seems to be very lengthy
@lallu12343
@lallu12343 5 жыл бұрын
Thanks Tushar sir for explaining, Heap is not the most appropriate data structure to be used in this problem, this is a classic use case for ordered_map, I was silly to think this could be replaced with ordered_set but didn't consider the case of duplicate heights. TreeMap() is the solution.
@baurks
@baurks 4 жыл бұрын
This is great. Finally I am able to solve the problem following your video. Thanks so much!
@prajaktakarandikar3459
@prajaktakarandikar3459 3 жыл бұрын
Anytime the height changes, add the x coordinate and the current max height to the answer.
@manojamrutharaj9071
@manojamrutharaj9071 4 жыл бұрын
Great explanation Tushar, content is clear with enough Algo tracing examples. I always learn some stuff from your videos. Thanks!
@mbuchove
@mbuchove 3 жыл бұрын
Consistently excellent explanations!
@vijendrakumarsharma5250
@vijendrakumarsharma5250 4 жыл бұрын
c++ : can be done via multiset and few implementation changes.. idea is same as above
@kakkwxt3653
@kakkwxt3653 8 жыл бұрын
youtube上讲算法最清楚的频道了。。。膝盖收下
@yuhaokong
@yuhaokong 7 жыл бұрын
加我一個
@anshuman1964
@anshuman1964 5 жыл бұрын
你是对的
@Charles-rn3ke
@Charles-rn3ke 5 жыл бұрын
这哥们在难题上讲的都比华语的频道清楚。
@BullishBuddy
@BullishBuddy 5 жыл бұрын
translate: This is the clearest explanation among all algo videos on KZbin. Please accept my knees.
@pullrequest1296
@pullrequest1296 4 жыл бұрын
如果能吧口音纠正一下,就完美了
@aj_prakash
@aj_prakash 6 жыл бұрын
Thank you very much for this amazing explanation. Super clear and explained all the edge cases well.
@firenutz698
@firenutz698 4 жыл бұрын
Tushar you explained really well I just wish I could see this solution as easy as you did lol
@nirmalgurjar8181
@nirmalgurjar8181 7 ай бұрын
All 3 edge cases are covered if we mark -ve height for start the building and now if starts are same then height can be matched.
@miketsubasa3611
@miketsubasa3611 4 жыл бұрын
Great Explanation.your explanations are always superb.concept explanation,then edge cases,and then code explanation makes them complete
@phoenix2623
@phoenix2623 4 жыл бұрын
Thanks for the video, amazing explanation!! Another case handled inadvertently by the comparator, and is worth mentioning is that, if this.x == other.x && this. height == other.height, the point that has isStart = true comes before the point with isStart = false, in order to avoid errorenously flipping the height back to lower and making a wrong critical point in result. Thanks!
@Madeinchinaagain
@Madeinchinaagain 2 жыл бұрын
Thanks for pointing this out! I was wondering about this case, too. 2 years later, your comment came in handy!
@junnunsafoan3977
@junnunsafoan3977 3 жыл бұрын
Tushar is LC Legend.
@Kavishkhullar
@Kavishkhullar 3 жыл бұрын
saw the compareTo method you wrote. It's a great implementation.
@tsukisos
@tsukisos 8 жыл бұрын
Hey, thanks a lot Tushar! Your explaination for the edge cases helped me solve the bugs I've been having for a whole day, LOL.. Keep it up buddy!
@yangli6597
@yangli6597 3 жыл бұрын
Veryyyyyy clear about this problem!!! Thanks a lot.
@deathbombs
@deathbombs 2 жыл бұрын
If we wanted to use priorityQueue instead of TreeMap, would this help optimize? PQ Current solution to clarify is: TreeMap
@chrisniuniu
@chrisniuniu 8 жыл бұрын
Thank you very much Tushar sir, you are the best!!!
@lakshaydulani
@lakshaydulani 6 жыл бұрын
nice question..i thought of the same algo.. happy to see it getting verified here
@meghna1320
@meghna1320 3 жыл бұрын
Thanks Tushar, this is very helpful!
@Atpugtihsrah
@Atpugtihsrah 3 жыл бұрын
Can't thank you enough for this great explanation!
@nairchannel3753
@nairchannel3753 3 жыл бұрын
Couldn't be done better . Thanks .
@mercuriallabs9
@mercuriallabs9 4 жыл бұрын
good solution, but I feel the time complexity depends a lot on the priority queue implementation. I have not come across any implementation of priority queue that supports delete operation in real world in O(logn). So lets suppose deletion is supported in O(x). Then time complexity of solution becomes O(n.x).
@TheAsltech
@TheAsltech 8 жыл бұрын
great work Tushar..
@darthvader_
@darthvader_ 3 жыл бұрын
Great Explanation
@sengineer2554
@sengineer2554 6 жыл бұрын
Dude this is amazing, thanks for sharing it with us
@mukhtarbimurat5106
@mukhtarbimurat5106 4 жыл бұрын
Thank you very match! Very clear, especially edge cases!
@sj_wanders
@sj_wanders 6 жыл бұрын
Thank you, Tushar. It's an old video but still so useful.
@smanjunath14
@smanjunath14 5 жыл бұрын
Great explanation thanks for sharing
@herculean6748
@herculean6748 2 жыл бұрын
Great explanation!!
@indrajitbanerjee5131
@indrajitbanerjee5131 4 жыл бұрын
Nice explanation.
@poojaprasanthi1272
@poojaprasanthi1272 3 жыл бұрын
Thanks Tushar
@sabeernitb
@sabeernitb 8 жыл бұрын
Awesome explanation Tushar!!
@vijay19841000
@vijay19841000 8 жыл бұрын
Thanks a lot Tushar. Your explanation was really helpful.
@mylotundinho
@mylotundinho 4 жыл бұрын
Top man! This is great!
@kanthravivvn
@kanthravivvn 5 жыл бұрын
clear explanation Tushar. Keep up the good work !!
@shreyas.kulkarni
@shreyas.kulkarni 7 жыл бұрын
Have a feeling that PQ/heap is an overfit for this problem. If the given input of n intervals is exploded to 2n entries with x1:y and (x2-1):y, then sorted on x, and then deduped for x and y both (with different rules) and expanded for missing entries in that deduping pass itself, we can still get to an O(nlogn) worst case.
@talivanov93
@talivanov93 4 жыл бұрын
Great explanation. Thank you!
@AishwaryaRadhakrishnan34
@AishwaryaRadhakrishnan34 4 жыл бұрын
Amazing! Very Helpful !
@cashflow9156
@cashflow9156 8 жыл бұрын
Great video
@kaichenghu3826
@kaichenghu3826 5 жыл бұрын
hey man, this is crystal clear
@itsjensenkuo
@itsjensenkuo 8 жыл бұрын
Awesome tutorial.
@qihan5022
@qihan5022 4 жыл бұрын
Best and clearest! TY!
@pianochannel100
@pianochannel100 4 жыл бұрын
God bless you, you magnificent bastard.
@reshmichowdhury5189
@reshmichowdhury5189 7 жыл бұрын
Great video. Many thanks for taking time to upload this great video.
@motivation_hubPJ
@motivation_hubPJ 4 жыл бұрын
Thanks a lot tushar
@SudeeptaSood
@SudeeptaSood 3 жыл бұрын
thanks tushar!
@joshuamelo2010
@joshuamelo2010 5 жыл бұрын
Very good video
@qiwang8640
@qiwang8640 5 жыл бұрын
Thanks a lot! Really Helpful!
@tanufive
@tanufive 7 жыл бұрын
if we use priorityQueue then there is no way to maintain a counter for height repetition and i guess its required to have that. So PQ is not an option
@RagazzoKZ
@RagazzoKZ 5 жыл бұрын
You are absolutely right!
@tomislavzoricic5656
@tomislavzoricic5656 8 жыл бұрын
Great explanation!
@marriagedance8657
@marriagedance8657 4 жыл бұрын
great video!
@yunierperez2680
@yunierperez2680 8 жыл бұрын
Excellent explanation! Are you going to include a divide & conquer solution for this problem in some other video?
@swapneshchaubal351
@swapneshchaubal351 6 жыл бұрын
Thanks for the videos dude, appreciate all the hard work you do. Cheers!
@yh28789
@yh28789 8 жыл бұрын
This is a really good video!
@lingyongwang2817
@lingyongwang2817 7 жыл бұрын
very nice explanation!
@patyogesh20
@patyogesh20 6 жыл бұрын
It's not clear what will be the KEY & VALUE in TreeMap though? And, thank you for great explanation
@kathansanghavi5451
@kathansanghavi5451 2 жыл бұрын
Thank you very much !!
@wanghaochen3515
@wanghaochen3515 8 жыл бұрын
Just one thing, how are you supposed to remove an element from a priority queue if it wasn't the head of it? There's no way to iterate a c++ STL or Java queue. I think a better explanation is a max heap not a priority queue.
@tsukisos
@tsukisos 8 жыл бұрын
In c++ you can use std::multiset
@vivekdhandha3425
@vivekdhandha3425 4 жыл бұрын
Thanks a ton!
@akanshkumar2876
@akanshkumar2876 4 жыл бұрын
absolute god
@shiwanggupta8608
@shiwanggupta8608 6 жыл бұрын
use multiset if you are implementing it in c++
@algorithmimplementer415
@algorithmimplementer415 5 жыл бұрын
@Tushar Roy - Coding Made Simple Why did you say that remove from priority queue is not log(n) ?
@crystinaxinyuzhang3621
@crystinaxinyuzhang3621 4 жыл бұрын
yet how do u remove a non-largest element from the height max-heap?
@briankarcher8338
@briankarcher8338 2 жыл бұрын
That's the million dollar question. When to, and not to, use a particular data class.
Buy/Sell Stock With K transactions To Maximize Profit Dynamic Programming
29:09
Tushar Roy - Coding Made Simple
Рет қаралды 177 М.
Binary Search : Median of two sorted arrays of different sizes.
24:48
Tushar Roy - Coding Made Simple
Рет қаралды 549 М.
А я думаю что за звук такой знакомый? 😂😂😂
00:15
Денис Кукояка
Рет қаралды 3,1 МЛН
Real Man relocate to Remote Controlled Car 👨🏻➡️🚙🕹️ #builderc
00:24
Don't underestimate anyone
00:47
奇軒Tricking
Рет қаралды 15 МЛН
Find the Skyline Problem with C++ Solution Explained
10:49
mCoding
Рет қаралды 49 М.
Segment Tree Range Minimum Query
27:44
Tushar Roy - Coding Made Simple
Рет қаралды 278 М.
The Skyline Problem
19:37
IDeserve
Рет қаралды 38 М.
Burst Balloon Dynamic Programming[Leetcode]
27:22
Tushar Roy - Coding Made Simple
Рет қаралды 104 М.
Minimum Height Trees - Leetcode 310 - Python
23:30
NeetCodeIO
Рет қаралды 21 М.
The LeetCode Fallacy
6:08
NeetCode
Рет қаралды 574 М.
Text Justification Dynamic Programming
15:31
Tushar Roy - Coding Made Simple
Рет қаралды 143 М.
The Traveling Salesman Problem: When Good Enough Beats Perfect
30:27
Trie Data Structure
19:40
Tushar Roy - Coding Made Simple
Рет қаралды 412 М.
Disjoint Sets using union by rank and path compression Graph Algorithm
17:49
Tushar Roy - Coding Made Simple
Рет қаралды 315 М.
А я думаю что за звук такой знакомый? 😂😂😂
00:15
Денис Кукояка
Рет қаралды 3,1 МЛН