@Elias Productions Exactly just use a (maybe a little verbose) name instead of a comment. If something too verbose it's also a good indicator for a second look for refactoring. Also a verbose name is inconvenient when used often. In that case again, maybe a candidate for refactoring. Also I noticed that I often wrote comments at the call site where I used it (e.g. because expect weird side effects). Using the name makes that redundant too.
I was thinking the same thing like half a year ago. He'll get there. He was at just thousand or so subs before and I was in shock. If he keeps making great vids, getting views, likes, comments, he'll get 100k in no time.
Could you work on making the visuals appear alongside the code sometimes? Especially for explaining logic portions like when you explain popTallestUntilRight...()
Is putting the return type on its own line something typical? I'm pretty new to C++ and I've not seen that style before. Thanks for the example, I'll give it a try.
That's from the GNU style guide for Linux application programming, so that you don't have search for function names while looking at someone else's code.
C89 style function returns. Modern way to return (C++11 and up, if your compiler supports it) is auto FunctionName(param a, param b) -> return_type { // code } (capitalization may vary according to your style)
@mCoding, this is a great video as always! You mentioned in a comment that you are looking for ideas for a more general audience. IMHO the more basic or introductory the content the more people interested in it. Of course defining that is complicated. Basic C++ may be harder than intermediate Python, idk. But making intro tutorials of C++ and/or Python (or Julia) maybe a good way to reach a wider audience. I, for example, would love to see a tutorial on some graphical library in C++. How to do in C++ the kind of plots that can be done in Python or MATLAB or Octave, etc. Just an idea.
Hi! This gives a hint to the compiler that I believe an exception will never be thrown during the execution of the function. It allows for additional optimizations by the compiler because that means the compiler doesn't have to add any extra code preparing for stack-unwinding when a potential exception is thrown. If you mark a function noexcept and it does end up throwing an exception though, your program is terminated by calling std::terminate or std::unexpected.
@@mCoding I see ! So I should always use noexcept for very simple functions that I know will never throw an exception, like the getters ? Thanks so much for the response :)
Here's how I did it: Put all the buildings in a priority_queue. Keep track of the tallest building till now. If you encounter a "collision" with the tallest building till now, either you are taller than it, or you are shorter, or equal. If you are taller, congrats! Push yourself into the solution, and now you're the tallest building till now. If you're shorter, well maybe not for long! We "trim" the building (building.startX = tallest_building.endX) and push it back into the priority_queue because it may become a contender of the skyline later on. If you're equal in height, then nothing to push, but you're the tallest building till now. Oh and also in case where you are taller, you need to "trim" the ex-tallest building too as it may also become tallest again later on (ofcourse only trim if it is wider and stretches beyond the newest tallest building's right endpoint).
Why is everything marked as static? I would think that this class is a single instance class so static doesn't seem that useful. Is there some optimization benefit to making the members static?
The algorithm does not maintain any state so logically it is static. The real answer here though is that it shouldnt even be inside a class, it should just be free functions. But leetcode wants it in a class.
Using a vector for what is clearly a struct is not only suboptimal, it also makes the code less clear. At first I thought these vectors were the whole list of inputs.
I had the same misconception when I first saw the problem. I had the biggest visible confusion face in a long time after realizing it was just left right height
My first reaction when I saw the Building with 3 fields being represented as an std::vector, was also "Seriously why, LeetCode?" Thanks for pointing that out!
Big fan of the channel, and am a somewhat avid Pythonista, but am interested in learning C++. I'm already fairly proficient in C. Any advice on where to start learning?
I don't know, I think relative performance is much more important to leetcode than the literal number of milliseconds. Because of this, forcing the use of slower data types isn't an issue IMO
I have to disagree, performance in C++ often (and certainly in this case) comes down to counting heap allocations and cache misses. If you replaced vector with array in everyone's answer you would not find that everyone's answer kept it's relative position.
The buildings being sorted by left coordinate was one of the assumptions of the problem. If you want to allow unsorted buildings, then just sort them first and proceeed.
I'm not sure was this done for performance or not, but test code is so copy-pasted. I believe you could use a single function to run all tests, passing an array of tuples "input -> output".
5:57 ahh yes verbose function naming
I spent a long time trying to think of a descriptive shorter name, but alas I did not succeed. Sometimes that's just how it goes.
@@mCoding function name != function description
@Elias Productions Exactly just use a (maybe a little verbose) name instead of a comment. If something too verbose it's also a good indicator for a second look for refactoring.
Also a verbose name is inconvenient when used often. In that case again, maybe a candidate for refactoring.
Also I noticed that I often wrote comments at the call site where I used it (e.g. because expect weird side effects). Using the name makes that redundant too.
Your gig might be python, but I see a bright future in your C++ content. Keep it up
Thank you very much for your kind words! I will definitely do my best to keep it up.
Loving this sort of content, more competitive programming/alg/ds lectures would be appreciated!
The quality of your videos is superb. I truly don't understand how you don't have more subscribers. Cheers.
Thanks so much! I know I haven't figured out how to grab a general audience's attention for very long. Working on it and always open to suggestions!
I was thinking the same thing like half a year ago. He'll get there. He was at just thousand or so subs before and I was in shock. If he keeps making great vids, getting views, likes, comments, he'll get 100k in no time.
@@justingolden21 you were right!!
Could you work on making the visuals appear alongside the code sometimes? Especially for explaining logic portions like when you explain popTallestUntilRight...()
Yeah this is where the video lost me. I try to visualize everything, but at some point I couldn't anymore.
Is putting the return type on its own line something typical? I'm pretty new to C++ and I've not seen that style before. Thanks for the example, I'll give it a try.
This is "needs to fit on screen even when the font is large" style. Not sure if anyone does this in normal code
Apparently this is some old school C formatting www.gnu.org/prep/standards/standards.html#Formatting
As example, this is the coding style used in CPython. So it is somewhat common at least.
That's from the GNU style guide for Linux application programming, so that you don't have search for function names while looking at someone else's code.
C89 style function returns. Modern way to return (C++11 and up, if your compiler supports it) is
auto FunctionName(param a, param b) -> return_type
{ // code }
(capitalization may vary according to your style)
YT algorithm boost
@mCoding, this is a great video as always! You mentioned in a comment that you are looking for ideas for a more general audience. IMHO the more basic or introductory the content the more people interested in it. Of course defining that is complicated. Basic C++ may be harder than intermediate Python, idk. But making intro tutorials of C++ and/or Python (or Julia) maybe a good way to reach a wider audience. I, for example, would love to see a tutorial on some graphical library in C++. How to do in C++ the kind of plots that can be done in Python or MATLAB or Octave, etc. Just an idea.
Thanks I appreciate the ideas!
that excited voice at the end was amazing
Hi , I'm a bit of a cpp newbie, why does he use noexcept for the getter functions ?
Hi! This gives a hint to the compiler that I believe an exception will never be thrown during the execution of the function. It allows for additional optimizations by the compiler because that means the compiler doesn't have to add any extra code preparing for stack-unwinding when a potential exception is thrown. If you mark a function noexcept and it does end up throwing an exception though, your program is terminated by calling std::terminate or std::unexpected.
@@mCoding I see ! So I should always use noexcept for very simple functions that I know will never throw an exception, like the getters ? Thanks so much for the response :)
Gonna try this when I get home! I haven’t done C++ in a long while. What’s a better ice breaker than a good ol’ algorithm
Although I only know Python, I appreciated your detailed explanations. Great video!
Here's how I did it:
Put all the buildings in a priority_queue. Keep track of the tallest building till now. If you encounter a "collision" with the tallest building till now, either you are taller than it, or you are shorter, or equal.
If you are taller, congrats! Push yourself into the solution, and now you're the tallest building till now.
If you're shorter, well maybe not for long! We "trim" the building (building.startX = tallest_building.endX) and push it back into the priority_queue because it may become a contender of the skyline later on.
If you're equal in height, then nothing to push, but you're the tallest building till now.
Oh and also in case where you are taller, you need to "trim" the ex-tallest building too as it may also become tallest again later on (ofcourse only trim if it is wider and stretches beyond the newest tallest building's right endpoint).
I got 100% in runtime (7ms) and 98% in memory
I love your visualization!
Why is everything marked as static? I would think that this class is a single instance class so static doesn't seem that useful. Is there some optimization benefit to making the members static?
The algorithm does not maintain any state so logically it is static. The real answer here though is that it shouldnt even be inside a class, it should just be free functions. But leetcode wants it in a class.
Interesting content, looking forward to seeing more C++ on your channel!
What code editor/IDE are you using in your videos?
Vscode in this video
@@mCoding Thank you. I see you also say PyCharm in another video. I like the theme.
Using a vector for what is clearly a struct is not only suboptimal, it also makes the code less clear. At first I thought these vectors were the whole list of inputs.
I had the same misconception when I first saw the problem. I had the biggest visible confusion face in a long time after realizing it was just left right height
5:57 popTallestUntilRightExceedsCurrentTallestRightAndUpdateSkyline :D
Unashamed :D
My first reaction when I saw the Building with 3 fields being represented as an std::vector, was also "Seriously why, LeetCode?" Thanks for pointing that out!
Big fan of the channel, and am a somewhat avid Pythonista, but am interested in learning C++. I'm already fairly proficient in C. Any advice on where to start learning?
Waiting for more videos like this :)
how hard would it be to include "concave" shapes, "flying objects" and/or balcony above the camera?
I don't know, I think relative performance is much more important to leetcode than the literal number of milliseconds. Because of this, forcing the use of slower data types isn't an issue IMO
I have to disagree, performance in C++ often (and certainly in this case) comes down to counting heap allocations and cache misses. If you replaced vector with array in everyone's answer you would not find that everyone's answer kept it's relative position.
If this was a competition about just number of steps scaling (like how we count big O) rather than time, I guess vectors/arrays won't matter?
Correct.
But how you can be sure that buildings are sorted? This whole algorithm collapses if they are not sorted
The buildings being sorted by left coordinate was one of the assumptions of the problem. If you want to allow unsorted buildings, then just sort them first and proceeed.
@@mCoding i've read description and didn't saw this assumption :(
Yoh do multiple comments from one person help with the UA-cam algorithm boost ?
Given what I know about how the neural network from 2016 was built, I'm guessing only one comment per user counts, but it probably doesn't hurt!
What is the "use" keyword doing?
I'm not sure was this done for performance or not, but test code is so copy-pasted. I believe you could use a single function to run all tests, passing an array of tuples "input -> output".
You're totally right, this was done out of pure laziness, not for performance :)
algo boost comment for good channel & video.
Feeding the YT algorithm
Solving skyline ? Easy -> scanline...:)
Snakes all over the world have a moment of silence.
No curves noted in the skyline
this is so much easier in Python.
Excellent
Thank you! Cheers!
Discord gang
Let's get some new members!
Discord gang by the way?
Help me
C/C++ >>>>>>> Python
Any day!
Gotta go fast!
Is that like a "extra right shift" operator? :D
@@osolomons It's so unsigned, it ignores signs you've never even heard of.
Except when development time is short and runtime not important.
Boooooost
I will never not be impressed by just how consistently ugly C++ is.
Great Vid Bro if you are not muslim Read About Islam❤
This code will return an incorrect skyline if buildings are not sorted by left wall positions.