f[0] is 1 which means there is only one way to build fp[0]: "no block". Thus you can just manually caculate f[0]~f[3] and f[4]=f[0]+f[1]+f[2]+f[3]=8
@user-yu6eq7pl2u3 ай бұрын
helper直接//2就好了 谢谢 代码很清楚
@juanghpx4 ай бұрын
Great explanation, helped me understand this difficult problem. Thanks for the effort you put into this video.
@MartinSteinausErding5 ай бұрын
Finally someone who describes the algorithm behind the solution. This is very well done.
@shivamshrey475 ай бұрын
python3 class Solution: def visibleMountains(self, peaks: List[List[int]]) -> int: # sort peaks in ascending order of (x - y) x-intercept # and also in descending order of (x + y) x-intercept peaks.sort(key=lambda x: ((x[0] - x[1]), -(x[0] + x[1]))) count = 0 max_end = float('-inf') for i, (x, y) in enumerate(peaks): if x + y > max_end: max_end = x + y if i < len(peaks) - 1 and peaks[i] == peaks[i + 1]: continue count += 1 return count
@josh-9976 ай бұрын
感谢分享,很清晰易懂的解释!
@EstherLi-05096 ай бұрын
Lulu did you come up with this solution independently? Such a genius
@CodeCode-pz6oo6 ай бұрын
No, I did reference to the official solution in Hackerrank. Yet, still needs lots of effort from my side to really understand the solution.
@xavierk997 ай бұрын
Hey Lulu, thanks for the explain. I didnt get why we are recursing the *width - the width* of each blocks in minute 7:36
@t0ny3607 ай бұрын
In the first step when calculating the number of ways you can build a single wall layer of length 6, why do we add the four previous ones? I don't understnad that part
@xialei32197 ай бұрын
Awesome solution and eloborated explanation, thanks for clarifying this problem!
@juanc941287 ай бұрын
Thank you very much, I was stucked
@nguyenngoctuan71497 ай бұрын
many thanks for your video
@dongyoonkim12117 ай бұрын
Thank you so much for this explanation. It really helped.
@Po-YuJuan7 ай бұрын
Very gorgeous and lucid! Thanks for saving time!
@rubikswiz8 ай бұрын
Awesome explanation Lulu!
@CodeCode-pz6oo8 ай бұрын
Thank you! 😃
@slava_xd8 ай бұрын
im confused about this "counter" variable. at 6:48 the median is 4 not 3.
@CodeCode-pz6oo8 ай бұрын
In the first 5 elements, the sorted window is = [2, 2, 3, 3, 4], so the median is the 3rd element (num3). And for the counter, the counter is the sum of frequency (cdf) up to the median number. For example, there are 2 of 2, 2 of 3, 1 of 4, so the sum of frequency up to 3rd element (cdf) is 2 + 2 = 4, and the median number is 3.
@HaroonRashid728 ай бұрын
Thank you. May you be blessed. I wanted logical help and it was the best resource. Rest of the internet had code.
@CodeCode-pz6oo8 ай бұрын
Glad it helped!
@jaylenzhang41988 ай бұрын
好欢乐,还有bgm
@sezerozer3828 ай бұрын
good
@CodeCode-pz6oo8 ай бұрын
Thanks
@TarasSlipets8 ай бұрын
Great explanation: well-structured, concise, with a practical walkthrough. Many thanks!
@CodeCode-pz6oo8 ай бұрын
You're very welcome!
@ethans25369 ай бұрын
omg you actually taught me😂, thanks a lot
@CodeCode-pz6oo8 ай бұрын
Happy to help!
@pandukasenevirathna95939 ай бұрын
great explanation. Thanks a lot. This is a harder question.
@himanshukrdiwedi45549 ай бұрын
Nice
@CodeCode-pz6oo9 ай бұрын
Thanks
@Doggy_Styles_Coding10 ай бұрын
nice coding keep it up ,)
@CodeCode-pz6oo10 ай бұрын
Thanks!
@letticonionepic10 ай бұрын
To those who are wondering: We counted (1, 3) combo as 4 but (3, 1) as 1 cuz if we break 3 in (3, 1) it will break into (1, 2, 1) and (2, 1, 1) which can already be covered by previous considerations from (2, 2) and (1, 3) so to avoid overlapping it has been done so.
@rayaqin7 ай бұрын
Imo your comment is misleading from the pattern of thought in the video. When making 4, it is true that: 2,2 breaks to 112, 211, 1111 (which would be 4 possibilites) and 3,1 breaks to 211, 121, 1111 (which would also be 4 possibilities) but in the explanation she didn't go through all the possible breaks, since she said we keep the first block in tact, and only look for possibilites with the rest of the blocks. You can see she marks the part that needs to be broken down with small diagonal lines. if the first block is a 1, we have 3, 21, 21 and 111, which is 4 possibilities if the first block is a 3, we only have 1 option left for the second block: 1. Thats why it is only 1 there.
@YosvanyBlanco10 ай бұрын
You did a great job explaining the intuition on this one thank you!
@CodeCode-pz6oo10 ай бұрын
Glad you enjoyed it!
@sanjanar919810 ай бұрын
Great explanation! thank you so much!!
@CodeCode-pz6oo10 ай бұрын
Glad you enjoyed it!
@leelashreerajendran872611 ай бұрын
Brute force solution : #assume the widest base and tallest mountain max_x = input[0][0] max_y = input[0][1] #calculate the widest base and tallest mountain for i in input: left_base = i[0]-i[1] right_base = i[0]+i[1] max_x = max(max_x, left_base) max_y = max(max_y, i[1]) #generate a 2D map of the scenery scenery = [[0 for i in range(max_y+1)] for j in range(-1*max_x, max_x + 1)] #populate the overlapping mountains for i in input: scenery[i[0]][i[1]] += 1 temp_y = i[1] - 1 counter = 1 while (temp_y > 0): for j in range(counter): scenery[i[0]-j][temp_y] += 1 scenery[i[0]+j][temp_y] += 1 counter += 1 temp_y -= 1 #Find the peaks which are not overlapped visible_mountain = 0 for i in input: if scenery[i[0]][i[1]] == 1: visible_mountain += 1 print(visible_mountain)
@astroswell11 ай бұрын
Thanks for the solution, Lulu! Could you please explain why is the total of ways to have a split in the wall is a multiplication of number of ways to build left-i and right-i?
@CodeCode-pz6oo11 ай бұрын
You can draw on a paper with hight = 1 and width of 4. When the i == 2, left side has 2 ways and right side also 2 ways, so the total is 2 *2.
@macolulu11 ай бұрын
Hi, Lulu. Greetings from Lulu.
@CodeCode-pz6oo11 ай бұрын
Hello!
@trlabhishekh347211 ай бұрын
The explanation was quite good, but it could have been even better with the code
@CodeCode-pz6oo11 ай бұрын
Thanks for the suggestion. Since so many people asking for the coding part, I'll upload a new video for coding recently.
@debochando Жыл бұрын
I am trying to solve this problem right now. Your video came in the right moment. Thank you so much.
@CodeCode-pz6oo Жыл бұрын
Glad it helped
@ANURAGSINGH-nl2ll Жыл бұрын
well explained thanks
@ybybyb8bo592 Жыл бұрын
28:11 total = 0,1,8,32(should be 64)
@CodeCode-pz6oo Жыл бұрын
Thanks for the correction.
@saurabhsingh6325 Жыл бұрын
Thanks for your nice explanation! <3
@CodeCode-pz6oo Жыл бұрын
My pleasure!
@rahulsawant2093 Жыл бұрын
Great Explanation, Thanks Keep it Up
@CodeCode-pz6oo Жыл бұрын
Thanks for liking
@DEEPAKKUMAR-xe2vb Жыл бұрын
Explanation was good but it would be more helpful if you explain the code too, Btw keep up the good work. 🙌🙌
@CodeCode-pz6oo Жыл бұрын
Ok next time
@_SAUBHAGYASINGH-yv1hp Жыл бұрын
if this is ur original voice then let me say your voice is very cute