Skip to content

Latest commit

 

History

History
252 lines (243 loc) · 51.6 KB

dynamic-programming.md

File metadata and controls

252 lines (243 loc) · 51.6 KB

Dynamic Programming LeetCode Problems

A collection of LeetCode problems solved using Dynamic Programming pattern techniques, explanations, and complexity analysis.

Problems

Easy

# Problem Language Time Space Explanation
392 Is Subsequence JavaScript, Python O(n) O(n) Explanation
463 Island Perimeter Python O(n) O(n) Explanation
495 Teemo Attacking Python O(n) O(n) Explanation
521 Longest Uncommon Subsequence I Python O(n) O(n) Explanation
674 Longest Continuous Increasing Subsequence Python O(n) O(n) Explanation
1332 Remove Palindromic Subsequences Python O(n) O(n) Explanation
1403 Minimum Subsequence in Non-Increasing Order Python O(n) O(n) Explanation
1971 Find if Path Exists in Graph JavaScript O(n) O(n) Explanation
2099 Find Subsequence of Length K With the Largest Sum Python O(n) O(n) Explanation
2180 Count Integers With Even Digit Sum Python O(n) O(n) Explanation
2325 Decode the Message Python O(n) O(n) Explanation
2389 Longest Subsequence With Limited Sum Python O(n) O(n) Explanation
2889 Reshape Data: Pivot Python O(n) O(n) Explanation
2890 Reshape Data: Melt Python O(n) O(n) Explanation
2900 Longest Unequal Adjacent Groups Subsequence I JavaScript O(n) O(n) Explanation
2951 Find the Peaks Python O(n) O(n) Explanation
3285 Find Indices of Stable Mountains JavaScript O(n) O(n) Explanation
3903 Smallest Stable Index I JavaScript O(n) O(n) Explanation
4056 Number of Intersecting Interval Pairs I Python O(n) O(n) Explanation

Medium

# Problem Language Time Space Explanation
72 Edit Distance JavaScript, Python O(n) O(n) Explanation
91 Decode Ways JavaScript O(n) O(n) Explanation
97 Interleaving String JavaScript, Python O(n) O(n) Explanation
120 Triangle JavaScript O(n) O(n) Explanation
221 Maximal Square JavaScript O(n) O(n) Explanation
279 Perfect Squares Python O(n) O(n) Explanation
322 Coin Change JavaScript O(n) O(n) Explanation
334 Increasing Triplet Subsequence JavaScript O(n) O(n) Explanation
368 Largest Divisible Subset JavaScript O(n) O(n) Explanation
375 Guess Number Higher or Lower II Python O(n) O(n) Explanation
376 Wiggle Subsequence Python O(n) O(n) Explanation
416 Partition Equal Subset Sum JavaScript O(n) O(n) Explanation
474 Ones and Zeroes Python O(n) O(n) Explanation
478 Generate Random Point in a Circle Python O(n) O(n) Explanation
486 Predict the Winner C++ O(n) O(n) Explanation
516 Longest Palindromic Subsequence Python O(n) O(n) Explanation
518 Coin Change II Python O(n) O(n) Explanation
522 Longest Uncommon Subsequence II Python O(n) O(n) Explanation
583 Delete Operation for Two Strings Python O(n) O(n) Explanation
673 Number of Longest Increasing Subsequence JavaScript O(n) O(n) Explanation
688 Knight Probability in Chessboard Python O(n) O(n) Explanation
712 Minimum ASCII Delete Sum for Two Strings Python O(n) O(n) Explanation
718 Maximum Length of Repeated Subarray Python O(n) O(n) Explanation
740 Delete and Earn Python O(n) O(n) Explanation
764 Largest Plus Sign Python O(n) O(n) Explanation
790 Domino and Tromino Tiling JavaScript O(n) O(n) Explanation
808 Soup Servings JavaScript O(n) O(n) Explanation
813 Largest Sum of Averages Python O(n) O(n) Explanation
869 Reordered Power of 2 Python O(n) O(n) Explanation
931 Minimum Falling Path Sum JavaScript O(n) O(n) Explanation
935 Knight Dialer Python O(n) O(n) Explanation
983 Minimum Cost For Tickets Python O(n) O(n) Explanation
985 Sum of Even Numbers After Queries Python O(n) O(n) Explanation
1027 Longest Arithmetic Subsequence Python O(n) O(n) Explanation
1033 Moving Stones Until Consecutive Python O(n) O(n) Explanation
1039 Minimum Score Triangulation of Polygon Python O(n) O(n) Explanation
1040 Moving Stones Until Consecutive II Python O(n) O(n) Explanation
1043 Partition Array for Maximum Sum Python O(n) O(n) Explanation
1049 Last Stone Weight II Python O(n) O(n) Explanation
1105 Filling Bookcase Shelves Python O(n) O(n) Explanation
1140 Stone Game II C++ O(n) O(n) Explanation
1143 Longest Common Subsequence JavaScript O(n) O(n) Explanation
1155 Number of Dice Rolls With Target Sum Python O(n) O(n) Explanation
1262 Greatest Sum Divisible by Three Python O(n) O(n) Explanation
1268 Search Suggestions System JavaScript O(n) O(n) Explanation
1315 Sum of Nodes with Even-Valued Grandparent Python O(n) O(n) Explanation
1423 Maximum Points You Can Obtain from Cards Python O(n) O(n) Explanation
1626 Best Team With No Conflicts JavaScript O(n) O(n) Explanation
1641 Count Sorted Vowel Strings JavaScript O(n) O(n) Explanation
1648 Sell Diminishing-Valued Colored Balls Python O(n) O(n) Explanation
1690 Stone Game VII Python O(n) O(n) Explanation
1824 Minimum Sideway Jumps Python O(n) O(n) Explanation
1911 Maximum Alternating Subsequence Sum Python O(n) O(n) Explanation
1937 Maximum Number of Points with Cost Python O(n) O(n) Explanation
1947 Maximum Compatibility Score Sum JavaScript O(n) O(n) Explanation
1958 Check if Move is Legal Python O(n) O(n) Explanation
1959 Minimum Total Space Wasted With K Resizing Operations JavaScript O(n) O(n) Explanation
1986 Minimum Number of Work Sessions to Finish the Tasks JavaScript O(n) O(n) Explanation
1997 First Day Where You Have Been in All the Rooms Python O(n) O(n) Explanation
2008 Maximum Earnings From Taxi Python O(n) O(n) Explanation
2140 Solving Questions With Brainpower Python O(n) O(n) Explanation
2201 Count Artifacts That Can Be Extracted JavaScript O(n) O(n) Explanation
2207 Maximize Number of Subsequences in a String JavaScript O(n) O(n) Explanation
2266 Count Number of Texts Python O(n) O(n) Explanation
2304 Minimum Path Cost in a Grid Python O(n) O(n) Explanation
2311 Longest Binary Subsequence Less Than or Equal to K Python O(n) O(n) Explanation
2369 Check if There is a Valid Partition For The Array Python O(n) O(n) Explanation
2370 Longest Ideal Subsequence Python O(n) O(n) Explanation
2466 Count Ways To Build Good Strings Python O(n) O(n) Explanation
2555 Maximize Win From Two Segments Python O(n) O(n) Explanation
2761 Prime Pairs With Target Sum JavaScript O(n) O(n) Explanation
2767 Partition String Into Minimum Beautiful Substrings Python O(n) O(n) Explanation
2770 Maximum Number of Jumps to Reach the Last Index C++ O(n) O(n) Explanation
2787 Ways to Express an Integer as Sum of Powers Python O(n) O(n) Explanation
2825 Make String a Subsequence Using Cyclic Increments JavaScript O(n) O(n) Explanation
2896 Apply Operations to Make Two Strings Equal JavaScript O(n) O(n) Explanation
2901 Longest Unequal Adjacent Groups Subsequence II JavaScript O(n) O(n) Explanation
2915 Length of the Longest Subsequence That Sums to Target JavaScript O(n) O(n) Explanation
2919 Minimum Increment Operations to Make Array Beautiful JavaScript O(n) O(n) Explanation
2925 Maximum Score After Applying Operations on a Tree JavaScript O(n) O(n) Explanation
2930 Number of Strings Which Can Be Rearranged to Contain Substring JavaScript O(n) O(n) Explanation
2944 Minimum Number of Coins for Fruits JavaScript O(n) O(n) Explanation
3040 Maximum Number of Operations With the Same Score II Python O(n) O(n) Explanation
3067 Count Pairs of Connectable Servers in a Weighted Tree Network JavaScript O(n) O(n) Explanation
3122 Minimum Number of Operations to Satisfy Conditions Python O(n) O(n) Explanation
3129 Find All Possible Stable Binary Arrays I JavaScript O(n) O(n) Explanation
3180 Maximum Total Reward Using Operations I Python O(n) O(n) Explanation
3201 Find the Maximum Length of Valid Subsequence I JavaScript O(n) O(n) Explanation
3202 Find the Maximum Length of Valid Subsequence II JavaScript O(n) O(n) Explanation
3290 Maximum Multiplication Score JavaScript O(n) O(n) Explanation
3316 Find Maximum Removals From Source String JavaScript O(n) O(n) Explanation
3332 Maximum Points Tourist Can Earn Python O(n) O(n) Explanation
3376 Minimum Time to Break Locks I Python O(n) O(n) Explanation
3409 Longest Subsequence With Decreasing Adjacent Difference Python O(n) O(n) Explanation
3418 Maximum Amount of Money Robot Can Earn Python O(n) O(n) Explanation
3428 Maximum and Minimum Sums of at Most Size K Subsequences JavaScript O(n) O(n) Explanation
3469 Find Minimum Cost to Remove Array Elements Python O(n) O(n) Explanation
3472 Longest Palindromic Subsequence After at Most K Operations Python O(n) O(n) Explanation
3603 Minimum Cost Path with Alternating Directions II Python O(n) O(n) Explanation
3627 Maximum Median Sum of Subsequences of Size 3 Python O(n) O(n) Explanation
3628 Maximum Number of Subsequences After One Inserting Python O(n) O(n) Explanation
3654 Minimum Sum After Divisible Sum Deletions Python O(n) O(n) Explanation
3685 Subsequence Sum After Capping Elements JavaScript O(n) O(n) Explanation
3693 Climbing Stairs II Python O(n) O(n) Explanation
3702 Longest Subsequence With Non-Zero Bitwise XOR C++ O(n) O(n) Explanation
3825 Longest Strictly Increasing Subsequence With Non-Zero Bitwise AND Python O(n) O(n) Explanation
3877 Minimum Removals to Achieve Target XOR Python O(n) O(n) Explanation
3882 Minimum XOR Path in a Grid Python O(n) O(n) Explanation
3946 Maximum Number of Items From Sale I Python O(n) O(n) Explanation
3979 Maximum Valid Pair Sum Python O(n) O(n) Explanation
3998 Transform Binary String Using Subsequence Sort JavaScript O(n) O(n) Explanation
4016 Maximum Area of Two Non-Overlapping Square Submatrices Python O(n) O(n) Explanation
4057 Number of Intersecting Interval Pairs II Python O(n) O(n) Explanation

Hard

# Problem Language Time Space Explanation
10 Regular Expression Matching JavaScript O(n) O(n) Explanation
115 Distinct Subsequences JavaScript O(n) O(n) Explanation
174 Dungeon Game JavaScript O(n) O(n) Explanation
312 Burst Balloons Python O(n) O(n) Explanation
472 Concatenated Words Python O(n) O(n) Explanation
546 Remove Boxes Python O(n) O(n) Explanation
552 Student Attendance Record II Python O(n) O(n) Explanation
629 K Inverse Pairs Array Python O(n) O(n) Explanation
664 Strange Printer Python O(n) O(n) Explanation
730 Count Different Palindromic Subsequences Python O(n) O(n) Explanation
741 Cherry Pickup JavaScript O(n) O(n) Explanation
805 Split Array With Same Average JavaScript O(n) O(n) Explanation
818 Race Car Python O(n) O(n) Explanation
879 Profitable Schemes Python O(n) O(n) Explanation
891 Sum of Subsequence Widths JavaScript O(n) O(n) Explanation
920 Number of Music Playlists JavaScript O(n) O(n) Explanation
940 Distinct Subsequences II JavaScript O(n) O(n) Explanation
956 Tallest Billboard Python O(n) O(n) Explanation
960 Delete Columns to Make Sorted III Python O(n) O(n) Explanation
1000 Minimum Cost to Merge Stones Python O(n) O(n) Explanation
1223 Dice Roll Simulation Python O(n) O(n) Explanation
1269 Number of Ways to Stay in the Same Place After Some Steps Python O(n) O(n) Explanation
1301 Number of Paths with Max Score PHP O(n) O(n) Explanation
1320 Minimum Distance to Type a Word Using Two Fingers Python O(n) O(n) Explanation
1340 Jump Game V C++ O(n) O(n) Explanation
1349 Maximum Students Taking Exam JavaScript O(n) O(n) Explanation
1388 Pizza With 3n Slices Python O(n) O(n) Explanation
1406 Stone Game III PHP O(n) O(n) Explanation
1416 Restore The Array Python O(n) O(n) Explanation
1420 Build Array Where You Can Find The Maximum Exactly K Comparisons JavaScript O(n) O(n) Explanation
1425 Constrained Subsequence Sum JavaScript O(n) O(n) Explanation
1434 Number of Ways to Wear Different Hats to Each Other JavaScript O(n) O(n) Explanation
1444 Number of Ways of Cutting a Pizza Python O(n) O(n) Explanation
1463 Cherry Pickup II JavaScript O(n) O(n) Explanation
1473 Paint House III Python O(n) O(n) Explanation
1478 Allocate Mailboxes JavaScript O(n) O(n) Explanation
1494 Parallel Courses II JavaScript O(n) O(n) Explanation
1510 Stone Game IV TypeScript O(n) O(n) Explanation
1547 Minimum Cost to Cut a Stick JavaScript O(n) O(n) Explanation
1595 Minimum Cost to Connect Two Groups of Points JavaScript O(n) O(n) Explanation
1687 Delivering Boxes from Storage to Ports JavaScript O(n) O(n) Explanation
1697 Checking Existence of Edge Length Limited Paths Python O(n) O(n) Explanation
1713 Minimum Operations to Make a Subsequence Python O(n) O(n) Explanation
1723 Find Minimum Time to Finish All Jobs JavaScript O(n) O(n) Explanation
1761 Minimum Degree of a Connected Trio in a Graph JavaScript O(n) O(n) Explanation
1770 Maximum Score from Performing Multiplication Operations Python O(n) O(n) Explanation
1819 Number of Different Subsequences GCDs Python O(n) O(n) Explanation
1857 Largest Color Value in a Directed Graph JavaScript O(n) O(n) Explanation
1866 Number of Ways to Rearrange Sticks With K Sticks Visible Python O(n) O(n) Explanation
1879 Minimum XOR Sum of Two Arrays JavaScript O(n) O(n) Explanation
1883 Minimum Skips to Arrive at Meeting On Time Python O(n) O(n) Explanation
1900 The Earliest and Latest Rounds Where Players Compete Python O(n) O(n) Explanation
1955 Count Number of Special Subsequences Python O(n) O(n) Explanation
1987 Number of Unique Good Subsequences Python O(n) O(n) Explanation
2088 Count Fertile Pyramids in a Land Python O(n) O(n) Explanation
2172 Maximum AND Sum of Array Python O(n) O(n) Explanation
2188 Minimum Time to Finish the Race Python O(n) O(n) Explanation
2209 Minimum White Tiles After Covering With Carpets JavaScript O(n) O(n) Explanation
2218 Maximum Value of K Coins From Piles JavaScript O(n) O(n) Explanation
2312 Selling Pieces of Wood Python O(n) O(n) Explanation
2318 Number of Distinct Roll Sequences Python O(n) O(n) Explanation
2421 Number of Good Paths Python O(n) O(n) Explanation
2430 Maximum Deletions on a String Python O(n) O(n) Explanation
2463 Minimum Total Distance Traveled JavaScript O(n) O(n) Explanation
2484 Count Palindromic Subsequences Python O(n) O(n) Explanation
2518 Number of Great Partitions Python O(n) O(n) Explanation
2547 Minimum Cost to Split an Array Python O(n) O(n) Explanation
2585 Number of Ways to Earn Points Python O(n) O(n) Explanation
2646 Minimize the Total Price of the Trips JavaScript O(n) O(n) Explanation
2719 Count of Integers Python O(n) O(n) Explanation
2742 Painting the Walls Python O(n) O(n) Explanation
2809 Minimum Time to Make Array Sum At Most x JavaScript O(n) O(n) Explanation
2813 Maximum Elegance of a K-Length Subsequence Python O(n) O(n) Explanation
2842 Count K-Subsequences of a String With Maximum Beauty JavaScript O(n) O(n) Explanation
2945 Find Maximum Non-decreasing Array Length JavaScript O(n) O(n) Explanation
3077 Maximum Strength of K Disjoint Subarrays JavaScript O(n) O(n) Explanation
3082 Find the Sum of the Power of All Subsequences JavaScript O(n) O(n) Explanation
3130 Find All Possible Stable Binary Arrays II JavaScript O(n) O(n) Explanation
3165 Maximum Sum of Subsequence With Non-adjacent Elements Python O(n) O(n) Explanation
3181 Maximum Total Reward Using Operations II Python O(n) O(n) Explanation
3225 Maximum Score From Grid Operations Python O(n) O(n) Explanation
3287 Find the Maximum Sequence Value of Array Python O(n) O(n) Explanation
3320 Count The Number of Winning Sequences JavaScript O(n) O(n) Explanation
3336 Find the Number of Subsequences With Equal GCD PHP O(n) O(n) Explanation
3389 Minimum Operations to Make Character Frequencies Equal Python O(n) O(n) Explanation
3500 Minimum Cost to Divide Array Into Subarrays Python O(n) O(n) Explanation
3509 Maximum Product of Subsequences With an Alternating Sum Equal to K Python O(n) O(n) Explanation
3530 Maximum Profit from Valid Topological Order in DAG JavaScript O(n) O(n) Explanation
3538 Merge Operations for Minimum Travel Time Python O(n) O(n) Explanation
3539 Find Sum of Array Product of Magical Sequences JavaScript O(n) O(n) Explanation
3651 Minimum Cost Path with Teleportations Python O(n) O(n) Explanation
3681 Maximum XOR of Subsequences Python O(n) O(n) Explanation
3757 Number of Effective Subsequences Python O(n) O(n) Explanation
3883 Count Non Decreasing Arrays With Given Digit Sums Python O(n) O(n) Explanation
3886 Sum of Sortable Integers Python O(n) O(n) Explanation
3901 Good Subsequence Queries JavaScript O(n) O(n) Explanation
3957 Maximum Sum of M Non-Overlapping Subarrays II JavaScript O(n) O(n) Explanation
3989 Maximum Consistent Columns in a Grid Python O(n) O(n) Explanation
4068 Maximize Meeting Earnings with Idle Gaps Python O(n) O(n) Explanation