PRODUCT OF TWO RUN-LENGTH ENCODED ARRAYS | PYTHON | LEETCODE # 1868
Vložit
- čas přidán 9. 07. 2024
- In this video we are solving a popular Facebook and Twitter interview question: Product of Two Run-Length Encoded Arrays (Leetcode # 1868).
This is a pretty straightforward two pointer based solution though it may take seeing the solution once to be able to wrap your head around why it works and how this is truly the most optimal way to solve the question. - Věda a technologie
Perfect explanation :)
Nice explanation.
man good job explaining this one.
Thanks for the clear explanation and great video. My only comment is to use a pen rather than a mouse when you write. Good luck
Totally agree with you but the channel is still too small to warrant buying an iPad + magic pencil just to write a little bit cleaner. I see the video analytics and most people just jump to the code anyway so the cost/benefit of investing in that right now is not skewed in the right direction. I probably will eventually because using a mouse sucks 😂
@@crackfaang if I pass my upcoming interview, I will buy you an iPad + magic pencil ;)
Ty! I had the same intuition in terms of optimizating the solution, but couldn't translate it into code. How would you update your solution if modifying the input is not allowed?
Answering my own Q if anyone else wonders; we can create two additional variables to keep track of the frequencies; init these to the frequency for the first val/freq element of the encoded array (repsectveily); in each iteration, get the min frequency and substract these from the two variables. If their value is 0, advance their respective pointer, and retrieve the frequency only if their pointer is less than their respective encoded size.
I hope this helps others! and GL with your prep!
What about carry? say 9x9 = 81