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.
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.
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
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/
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, covering all the edge cases! Thanks a lot!
Glad it was helpful! To watch more videos like this visit nados.pepcoding.com
great explanation and that trick of using - for starting height
Superb explanation 🙌🙌
Amazing explanation ! Thank you !
This is awesome explanation. Keep it up.
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)
Awesome explanation sir
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/
Wonderful explaination
Glad you liked it.
Keep learning.
And for better experience and well organised content visit nados.pepcoding.com
Very good explanation bro 🔥
jordaar solution
Done!
Thanks a lot sir
Nice
Wonderful explanation sir
Glad it helped.
For better experience, visit nados.io, where you will get well curated content and career opportunities.
how to think first time ???
Impossible for first time unless you have seen such question before!
upload code in c++ also
This was a tough one