Was going through the editorial for 1 hour and got headache, this 20 mins explanation relieved me from the pain
@joydeeprony89 Жыл бұрын
What an explanation , You are a savior to this interview preparation universe.
@CS_n00b Жыл бұрын
please keep up these daily challenge solutions!
@the_witcherr275 Жыл бұрын
Very Helpful, Thanks Navdeep😉
@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 Жыл бұрын
Hi NeetCode. Members need domain driven design instructional videos. Thank you.
@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 Жыл бұрын
am so sad i didn't came up with a solution ,the problem looked too easy after this combinatorics solution Thank You .
@m.kamalali Жыл бұрын
If we do bottom up for recursive solution space can be optimized to o(1) " no need combinatorics"!
@OP-yw3ws Жыл бұрын
Thanks. I was so frustrated caz of this problem
@dattagangji7634 Жыл бұрын
Be regular bro. I love your content!
@王瀚君-c3j Жыл бұрын
Great explanation!
@pastori2672 Жыл бұрын
they definitely made this problem "Hard" because of the description
@Pegasus02Kr Жыл бұрын
I think I'm good with solution 1. 2 is confusing.
@orchlonchinbat2214 Жыл бұрын
Thank you. :)
@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 Жыл бұрын
Beautiful!!
@toriamfoobar Жыл бұрын
I don't really catch the use of Mod... Could you explain why we need it please?
@rajsuriyang3427 Жыл бұрын
I added them got the wrong answer. I guess i should multiply them.
@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