Number of Ways to Divide a Long Corridor - Leetcode 2147 - Python

  Рет қаралды 6,260

NeetCodeIO

NeetCodeIO

Күн бұрын

Пікірлер: 21
@jonaskhanwald566
@jonaskhanwald566 Жыл бұрын
Was going through the editorial for 1 hour and got headache, this 20 mins explanation relieved me from the pain
@joydeeprony89
@joydeeprony89 Жыл бұрын
What an explanation , You are a savior to this interview preparation universe.
@CS_n00b
@CS_n00b Жыл бұрын
please keep up these daily challenge solutions!
@the_witcherr275
@the_witcherr275 Жыл бұрын
Very Helpful, Thanks Navdeep😉
@1vader
@1vader Жыл бұрын
More efficient version of the combinatorial solution: MOD = 10**9 + 7 class Solution: def numberOfWays(self, corridor: str) -> int: total = 1 seats = 0 divider_spots = 1 for c in corridor: if seats == 2: if c == "P": divider_spots += 1 else: total = (total * divider_spots) % MOD divider_spots = 1 seats = 1 elif c == "S": seats += 1 if seats != 2: return 0 return total
@jasonswift7468
@jasonswift7468 Жыл бұрын
Hi NeetCode. Members need domain driven design instructional videos. Thank you.
@haoranliu517
@haoranliu517 Жыл бұрын
would be better if you can upload more videos for your pro members. Did not see Java solutions posted on your website. Great explanation. 😄
@yousrimeftah5768
@yousrimeftah5768 Жыл бұрын
am so sad i didn't came up with a solution ,the problem looked too easy after this combinatorics solution Thank You .
@m.kamalali
@m.kamalali Жыл бұрын
If we do bottom up for recursive solution space can be optimized to o(1) " no need combinatorics"!
@OP-yw3ws
@OP-yw3ws Жыл бұрын
Thanks. I was so frustrated caz of this problem
@dattagangji7634
@dattagangji7634 Жыл бұрын
Be regular bro. I love your content!
@王瀚君-c3j
@王瀚君-c3j Жыл бұрын
Great explanation!
@pastori2672
@pastori2672 Жыл бұрын
they definitely made this problem "Hard" because of the description
@Pegasus02Kr
@Pegasus02Kr Жыл бұрын
I think I'm good with solution 1. 2 is confusing.
@orchlonchinbat2214
@orchlonchinbat2214 Жыл бұрын
Thank you. :)
@arihantbedagkar7678
@arihantbedagkar7678 Жыл бұрын
Space Optimization to O(1): previous_seat_index = seats = 0 count = 1 for index, char in enumerate(corridor): if char == 'S': seats += 1 if seats > 2 and seats & 1: count = (count * (index - previous_seat_index)) % (10 ** 9 + 7) previous_seat_index = index return count if seats and not seats & 1 else 0
@NeetCodeIO
@NeetCodeIO Жыл бұрын
Beautiful!!
@toriamfoobar
@toriamfoobar Жыл бұрын
I don't really catch the use of Mod... Could you explain why we need it please?
@rajsuriyang3427
@rajsuriyang3427 Жыл бұрын
I added them got the wrong answer. I guess i should multiply them.
@ethanphelps5308
@ethanphelps5308 Жыл бұрын
yeah, the number of ways to place dividers between one pair is completely independent from the number of ways to place dividers between other pairs so the product rule applies for counting all possible orientations
@riyaz3409
@riyaz3409 Жыл бұрын
Daily Temperatures - Monotonic Stack - Leetcode 739 - Python
11:52
Don’t Choose The Wrong Box 😱
00:41
Topper Guild
Рет қаралды 15 МЛН
Симбу закрыли дома?! 🔒 #симба #симбочка #арти
00:41
Симбочка Пимпочка
Рет қаралды 5 МЛН
How to Fight a Gross Man 😡
00:19
Alan Chikin Chow
Рет қаралды 19 МЛН
1727. Largest Submatrix With Rearrangements | 3 Ways | O(m*n) time
31:00
K Inverse Pairs Array - Leetcode 629 - Python
29:44
NeetCodeIO
Рет қаралды 16 М.
Arithmetic Slices II - Leetcode 446 - Python
21:19
NeetCodeIO
Рет қаралды 17 М.
2 Years of C++ Programming
8:20
Zyger
Рет қаралды 8 М.
Freedom Trail - Leetcode 514 - Python
25:18
NeetCodeIO
Рет қаралды 14 М.
Greatest Common Divisor Traversal - Leetcode 2709 - Python
24:30
Student Attendance Record II - Leetcode 552 - Python
27:10
NeetCodeIO
Рет қаралды 9 М.
Dynamic Programming isn't too hard. You just don't know what it is.
22:31
DecodingIntuition
Рет қаралды 200 М.
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41