Recently i did Leetcode Longest Common Subsequence problem. I used the basic dp approach and solved it in 18 ms using 12 mb space. After that i decided to check the fastest solutions for the problem and got this code
Fastest LCS code
I submitted it and it ran in 4 ms using 7.5 mb space. I tried to deconstruct the algorithm and understand how it was working. I modified the code a bit and got it to run in 3 ms, but i still could not understand it.
My optimized code
I could not find any relevant blogs explaining it. Can anyone help me understand how this works or link any blogs. Thanks.