The Skyline Problem || Leetcode
ฝัง
- เผยแพร่เมื่อ 5 พ.ย. 2024
- Please consume this content on nados.pepcoding.com for a richer experience. It is necessary to solve the questions while watching videos, nados.pepcoding.com enables that.
NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. Pepcoding has taken the initiative to provide counselling and learning resources to all curious, skillful and dedicated Indian coders. This video is part of the series to impart industry-level web development and programming skills in the community.
We also provide professional courses with live classes and placement opportunities.
For more free study resources and information about the courses, visit: www.pepcoding....
Have a look at our result: www.pepcoding....
Follow us on our TH-cam page: / pepcoding
Follow us on our FB page: / pepcoding
Follow us on Instagram: / pepcoding
Follow us on LinkedIn: / pepcoding-education
Follow us on Pinterest: / _created
Follow us on Twitter: home
.
.
.
Happy Programming !!! Pep it up
.
.
.
#pepcoding #code #coder #codinglife #programming #coding #java #freeresources #datastrucutres #pepcode #competitive #competitiveprogramming #softwareengineer #engineering #engineer
subhesh sir, please jitna ho sake aap videos bna diya karo, aap ek baar explain kar dete ho toh 2 min mein code ho jaata hai, your explanation literally has magic, liked from 2 accounts
For C++ user :
If you are using priorityQueue in c++ stl u will not be able to solve this problem because there is no remove method in c++ stl priority quque so try to use multiset (not set because in edge test case some buildings start and point are same so make sure to use multiset) so for top element use *object_name.rbegin() and for remove element use find method to find element which u want to delete and after that use erase method thats it you solved problem.
Noted
CPP Code:
```
vector getSkyline(vector& buildings) {
vector res;
multiset pq{0};
vector points; // {start, -height} {end, height}
for(auto b : buildings) {
points.push_back({b[0],-b[2]});
points.push_back({b[1],b[2]});
}
sort(points.begin(),points.end());
int curHeight = 0;
for(int i=0;i
You earned a subscriber because of this explanation
great explanation and that trick of using - for starting height
Great explanation, covering all the edge cases! Thanks a lot!
Glad it was helpful! To watch more videos like this visit nados.pepcoding.com
Amazing explanation ! Thank you !
Superb explanation 🙌🙌
Awsome!!!
If start point of two rectangles is common, then sorting height in ascending order will not work I guess. Please correct me if I am wrong.
For example: {2,-6}, {2,-8}, {4, 6}, {7, 8}.
Now as heights are in ascending order, skyline would be: [2,6], [2,8], [7,0], right? or am I missing something.
watch from 20:17
u will have negative heights for start so the one with larger numeric value ie 8 will actually become -8 and so -8 < -6 hence u will get 8 height first
Thanks, got it
this solution is O(N^2) right? but the better approach is in O(NlogN)
This is awesome explanation. Keep it up.
Awesome explanation sir
Wonderful explaination
Glad you liked it.
Keep learning.
And for better experience and well organised content visit nados.pepcoding.com
Nice
What an explanation.Woaah👍
Glad you liked it.
For better experience and well organised content sign up on nados.io
And for being updated follow us on Instagram instagram.com/pepcoding/
Very good explanation bro 🔥
Thanks a lot sir
Done!
Wonderful explanation sir
Glad it helped.
For better experience, visit nados.io, where you will get well curated content and career opportunities.
jordaar solution
upload code in c++ also
how to think first time ???
Impossible for first time unless you have seen such question before!
This was a tough one