My favorite thing about calendars is that the number of days is always less than 32 bit... trying to plant the seed of thought without saying much more. & | ^
The writing of while True: on line 10 looks very dangerous. I suggest changing it to while curr: and then passing root into the insert() function on line 33.
It would be great if you could create a solution using segment tree .One of the primary reasons I always look forward for your videos is because how well and intuitively you carry out the explanation of some advanced implementation or its reasoning and I have to say this is what separates you from the other creators. So such high level of content is highly expected and appreciated from your side . Nonetheless I had been having an amazing time learning from you and immensely grateful to you for how far I have come.
I'm not sure about the O(n^2) complexity here. book checks through every element in events. It's time scales linearly with the size of events I think it should be o(n). Keep up the good work Neet. - A
Lets see step by step: - When there are no elements, just insert -- 0 comparison - to insert second element, you do 1 comparison - to insert third element, you do 2 comparisons in worst case - to insert fourth element, you do 3 comparisons in worst case and so on by the time you insert the nth element, you do 0 + 1 + 2 + ..... + (n-1) comparisons in the worst case which sums up to n(n-2)/2 ~= O(n^2). Hope that helps!
I think that also a SortedList could work, because we can have a list of integers (i will explain It later) and we can look of there Is a Number beetween the input, otherwise we will inser start and then end-1. [], then 1,10 [1, 9]
Hey man I don't know if you did that but could you please solve a problem about Segment Tree to teach us? Thanks
My favorite thing about calendars is that the number of days is always less than 32 bit... trying to plant the seed of thought without saying much more. & | ^
bitwise? 😅
Solved to using TreeSet! Pretty easy tbh if you know what a TreeSet / Map is.
one day gonna code like this
The writing of while True: on line 10 looks very dangerous. I suggest changing it to while curr: and then passing root into the insert() function on line 33.
It would be great if you could create a solution using segment tree .One of the primary reasons I always look forward for your videos is because how well and intuitively you carry out the explanation of some advanced implementation or its reasoning and I have to say this is what separates you from the other creators. So such high level of content is highly expected and appreciated from your side . Nonetheless I had been having an amazing time learning from you and immensely grateful to you for how far I have come.
I'm not sure about the O(n^2) complexity here. book checks through every element in events. It's time scales linearly with the size of events I think it should be o(n).
Keep up the good work Neet.
- A
Lets see step by step:
- When there are no elements, just insert -- 0 comparison
- to insert second element, you do 1 comparison
- to insert third element, you do 2 comparisons in worst case
- to insert fourth element, you do 3 comparisons in worst case and so on
by the time you insert the nth element, you do 0 + 1 + 2 + ..... + (n-1) comparisons in the worst case
which sums up to n(n-2)/2 ~= O(n^2).
Hope that helps!
Great explanation once again! Thank you for the daily.
I think that also a SortedList could work, because we can have a list of integers (i will explain It later) and we can look of there Is a Number beetween the input, otherwise we will inser start and then end-1.
[], then 1,10
[1, 9]
Hey Navi, do the interviewers allow us to use bisect_left/right methods? Sometimes these methods come very handy. Just wanted to be on the safe side.
THANKS NEETCODE
Can we also have a video for My Calendar 2? 🥰
Meet please can you solve problems with segment tree we really need this
Solved it!
I was doing this problem exactly 6 hours back 😂