Two corrections 1) 7:21 start>=end means interval does not exist,I missed explaining start == end case because end is exclusive range example [20,20] is invalid because range is actually 20 to 19 which is invalid. where as [16,20] is valid as the range is 16 to 19 2) 12:12 name of the algorithm is Line Sweep. Like target is 130, Please do like if you were able to understand the explanation as well as the code.
What if one interval is ending at 5 where we insert {5 , -1}and another interval starting at 5 where we insert {5,+1} .. Will it work for such case.. Like in this case insertion and deletion at same point will make the count as 0.. Will it work for such cases..??
It will work because we check in a loop right. ex: (3,5) and (5,9) map: 3 -> 1 5 -> 0 9 -> 1 count will be 0 initially. Now you can iterate and check. 1st iteration count will be 1 (when 3 is checked means there is one event) 2nd iteration count will be 1 (previous 1 + value of 5 is zero) 3rd iteration count will be 2 (previous 1 + value of 9 is one) your doubt was in the second iteration but how will it be zero? see, that is why we take prefix sum. that -1 from ending 5 was the +1 inserted by its starting moment not for next interval....
Two corrections
1) 7:21 start>=end means interval does not exist,I missed explaining start == end case because end is exclusive range example [20,20] is invalid because range is actually 20 to 19 which is invalid. where as [16,20] is valid as the range is 16 to 19
2) 12:12 name of the algorithm is Line Sweep.
Like target is 130, Please do like if you were able to understand the explanation as well as the code.
😍😍
Bhai aap boht he tagda pdha rhe ho ! Ye logic building itni strong kaise hogi ?
What if one interval is ending at 5 where we insert {5 , -1}and another interval starting at 5 where we insert {5,+1} .. Will it work for such case.. Like in this case insertion and deletion at same point will make the count as 0.. Will it work for such cases..??
It will work because we check in a loop right.
ex: (3,5) and (5,9)
map:
3 -> 1
5 -> 0
9 -> 1
count will be 0 initially.
Now you can iterate and check.
1st iteration count will be 1 (when 3 is checked means there is one event)
2nd iteration count will be 1 (previous 1 + value of 5 is zero)
3rd iteration count will be 2 (previous 1 + value of 9 is one)
your doubt was in the second iteration but how will it be zero?
see, that is why we take prefix sum.
that -1 from ending 5 was the +1 inserted by its starting moment not for next interval....
@@shashwat_tiwari_st Thank you sir.. Kuch naya sikhne koo mile firse..😇