Summary
Keywords
Full Transcript
Solve LeetCode 790 β Domino and Tromino Tiling using Dynamic Programming. We want the number of ways to tile a 2 Γ n board using: Domino (2Γ1) tiles (rotations allowed) Tromino (L-shape) tiles (rotations allowed) DP Idea A clean way is to use two states: full[i] = ways to fully tile a 2Γi board gap[i] = ways to tile a 2Γi board with one cell missing (a βstaggeredβ board) Recurrences: full[i] = full[iβ1] + full[iβ2] + 2Β·gap[iβ1] gap[i] = gap[iβ1] + full[iβ2] All answers are computed mod 1e9+7. (You can also derive the well-known single recurrence: full[i] = 2Β·full[iβ1] + full[iβ3], for i β₯ 3.) Complexity Time: O(n) Space: O(1) (rolling variables) If this helped, subscribe for more DP patterns and interview problems. #LeetCode #DynamicProgramming #Algorithms #codinginterview #leetcode #leetcodecoding #leetcodesolution #leetcodechallenge #faang #fang #computerscience #cs #codingtiktok #coding #codinglife #boostofhope #fyp #codinginterview #softwareengineer #swe #tech #foryou #python #learntocode #google #techtok #programming #algorithms #learntocode
