Answer: Reddit Associate Developer Interview Question 2025 April | Dynamic Programming |

Answer · Posted Jun 2026

Solution: Bottom-Up 2D Dynamic Programming Approach Define dp[i][j] as the length of the longest common subsequence of text1[0..i-1] and text2[0..j-1]. Two cases at each cell: if the current characters match (text1[i-1] == text2[j-1]), then dp[i][j] = 1 + dp[i-1][j-1] — we extend the LCS found so far by 1. If they do not match, take the best result without the current character from either string: dp[i][j] = max(dp[i-1][j], dp[i][j-1]). Base case: first row and column are all 0 (LCS of ...

The full answer & interview discussion are available to premium members.

Log in Create a free account