Pattern
Dynamic Programming
A compact view of archive entries grouped by recurring technique.
97 entries
97 entries tagged as Dynamic Programming.
14.04.2026
hard2463. Minimum Total Distance Traveled
Shortest distances to travel robots to factories
12.04.2026
hard1320. Minimum Distance to Type a Word Using Two Fingers
Min travel on keyboard to type a word
03.04.2026
hard3661. Maximum Walls Destroyed by Robots
Max walls hit, each robot shoot left or right
02.04.2026
medium3418. Maximum Amount of Money Robot Can Earn
Max sum path, 2 skips allowed
28.03.2026
hard2573. Find the String with LCP
Build string from longest common prefixes matrix
23.03.2026
medium1594. Maximum Non Negative Product in a Matrix
Max product path right-down
10.03.2026
hard3130. Find All Possible Stable Binary Arrays II
array to make with z zeros, o ones, l repeats
30.01.2026
hard2977. Minimum Cost to Convert String II
Min cost to convert string with transitions of substrings
28.01.2026
hard3651. Minimum Cost Path with Teleportations
Min cost to walk 2D grid with free teleports
10.01.2026
medium712. Minimum ASCII Delete Sum for Two Strings
Min removed sum to make strings equal
08.01.2026
hard1458. Max Dot Product of Two Subsequences
Max product of 2 subsequencies
03.12.2026
hard1411. Number of Ways to Paint N × 3 Grid
Ways to color 3xN grid
22.12.2025
hard960. Delete Columns to Make Sorted III
Remove columns to sort strings
17.12.2025
medium3573. Best Time to Buy and Sell Stock V
K best deals buy/short/sell stocks
06.12.2025
medium3578. Count Partitions With Max-Min Difference at Most K
Ways to partition into parts (max-min) at most k queue
27.11.2025
medium3381. Maximum Subarray Sum With Length Divisible by K
Max sum of %k-length subarray
26.11.2025
hard2435. Paths in Matrix Whose Sum Is Divisible by K
Paths in 2D matrix %k
18.11.2025
easy717. 1-bit and 2-bit Characters
Is '0' last from characters '0','10','11' concatenation
11.11.2025
medium474. Ones and Zeroes
Longest subsequence (ones,zeros) at most (m,n)
11.10.2025
medium3186. Maximum Total Damage With Spell Casting
Max sum of choosen values, skip v[i]+1+2-1-2
29.09.2025
medium1039. Minimum Score Triangulation of Polygon
Min sum of triangle product for every possible triangulation
25.09.2025
medium120. Triangle
Min path sum in triangle
12.09.2025
medium3227. Vowels Game in a String
Can Alice win Bob both removeing odd-even vowel count substring optimally
09.09.2025
medium2327. Number of People Aware of a Secret
People knowing a secret at day n, keeping delay then spread and forget
27.08.2025
hard3459. Length of Longest V-Shaped Diagonal Segment
Max length of 1-2-0-2.. diagonal sequence, on cw rotation
21.08.2025
medium1504. Count Submatrices With All Ones
Count islands of 1
20.08.2025
medium1277. Count Square Submatrices with All Ones
Count square islands of 1
12.08.2025
medium2787. Ways to Express an Integer as Sum of Powers
Ways to make n by sum of a^x+b^x+...
8.08.2025
medium808. Soup Servings
Probability A empty first plus both empty /2
31.07.2025
medium898. Bitwise ORs of Subarrays
Uniq OR-subarrays
28.07.2025
medium2044. Count Number of Maximum Bitwise-OR Subsets
Subsequencies with max OR
17.07.2025
medium3202. Find the Maximum Length of Valid Subsequence II
Longest same-pair-k-parity subsequence
8.07.2025
hard1751. Maximum Number of Events That Can Be Attended II
Max top k valued intervals search
2.07.2025
hard3333. Find the Original Typed String II
ways to remove duplicates, preserve length at least k
26.05.2025
hard1857. Largest Color Value in a Directed Graph
Max color freq path
23.05.2025
hard3068. Find the Maximum Sum of Node Values
Max sum by k-xoring edges
18.05.2025
hard1931. Painting a Grid With Three Different Colors
Ways to 3-color m n grid, no adjucents
16.05.2025
medium2901. Longest Unequal Adjacent Groups Subsequence II
Longest subsequence humming distance 1, alterating groups
14.05.2025
hard3337. Total Characters in String After Transformations II
t steps to convert char into next nums[c] chars
13.05.2025
medium3335. Total Characters in String After Transformations I
String length after t shifts c=c+1,z=ab
09.05.2025
hard3343. Count Number of Balanced Permutations
Permutations of even-odd position sums equal
05.05.2025
medium790. Domino and Tromino Tiling
Ways to fill 2xn board with I,L shapes
10.04.2025
hard2999. Count the Number of Powerful Integers
Numbers in range start..finish, digits up to limit
07.04.2025
medium416. Partition Equal Subset Sum
Two equal sum subsets
06.04.2025
medium368. Largest Divisible Subset
Longest all pairs divisible subset
01.04.2025
medium2140. Solving Questions With Brainpower
Max sum of (points, skip next) pairs
23.03.2025
medium1976. Number of Ways to Arrive at Destination
Count optimal paths from 0 to n - 1 ford
21.03.2025
medium2115. Find All Possible Recipes from Given Supplies
Valid recipes from supplies
28.02.2025
hard1092. Shortest Common Supersequence
Shortest string with both subsequences
24.01.2025
medium802. Find Eventual Safe States
Nodes without cycles
28.12.2024
hard689. Maximum Sum of 3 Non-Overlapping Subarrays
max non-intersecting intervals programming window
26.12.2024
medium494. Target Sum
Count signs permutations to sum equal target programming
31.10.2024
hard2463. Minimum Total Distance Traveled
Min robots[x] travel to factories[x,capacity] programming
30.10.2024
hard1671. Minimum Number of Removals to Make Mountain Array
Min removes to make a mountain programming search
27.10.2024
medium1277. Count Square Submatrices with All Ones
Count 1-filled squares in 2D matrix programming
21.08.2024
hard664. Strange Printer
Minimum continuous replacements to make a string programming
31.07.2024
medium1105. Filling Bookcase Shelves
Min total height to split [[w,h]] array by shelfWidth programming
25.05.2024
hard140. Word Break II
All string splits with dictionary programming
23.05.2024
medium2597. The Number of Beautiful Subsets
Count subsets without k difference in them
22.05.2024
medium131. Palindrome Partitioning
All palindrome partitions programming
21.05.2024
medium78. Subsets
All subsets
19.05.2024
hard3068. Find the Maximum Sum of Node Values
Max sum after xor k any edges in a tree
30.04.2024
medium1915. Number of Wonderful Substrings
Count substrings with at most one odd frequency manipulation
25.04.2024
medium2370. Longest Ideal Subsequence
Max length of less than k adjacent subsequence programming
10.02.2024
medium647. Palindromic Substrings
Count palindromes substrings.
08.02.2024
medium279. Perfect Squares
Min square numbers sum up to n.
03.02.2024
medium1043. Partition Array for Maximum Sum
Max sum of partition array into chunks size of at most k filled with max value in chunk.
26.01.2024
medium576. Out of Boundary Paths
Number of paths from cell in grid to out of boundary.
6.01.2024
hard1235. Maximum Profit in Job Scheduling
Max profit in non-intersecting jobs given startTime[], endTime[] and profit[].
29.11.2023
easy191. Number of 1 Bits
Bits count
08.11.2023
medium2849. Determine if a Cell Is Reachable at a Given Time
Is path possible on grid sx, sy -> fx, fy
03.11.2023
medium767. Reorganize String
Non-repeating consequent chars string from another string
28.10.2023
hard1220. Count Vowels Permutation
Count of n lengths paths according to graph rules a->e, e->(a, i), etc
27.10.2023
medium5. Longest Palindromic Substring
Longest palindrome substring
21.10.2023
hard1425. Constrained Subsequence Sum
Max sum of subsequence i - j <= k
13.10.2023
easy746. Min Cost Climbing Stairs
Classic DP: climbing stairs
9.09.2023
medium377. Combination Sum IV
Number of ways to sum up array nums to target
23.08.2023
medium767. Reorganize String
Create non repeated subsequent chars string from string
09.08.2023
medium2616. Minimize the Maximum Difference of Pairs
Minimum of maximums possible p diffs of distinct array positions
30.07.2023
hard664. Strange Printer
Minimum continuous overrides by the same character to make a string
24.06.2023
hard956. Tallest Billboard
Max sum of disjoint set in array
18.06.2023
hard2328. Number of Increasing Paths in a Grid
Count increasing paths in a matrix
28.05.2023
hard1547. Minimum Cost to Cut a Stick
Min cost of cuts c1,..,ci,..,cn of [0..n] where cut cost the length = to-from.
27.05.2023
hard1406. Stone Game III
Winner of “Alice”, “Bob” or “Tie” in game of taking 1, 2 or 3 stones by turn from stoneValue array.
13.05.2023
medium2466. Count Ways To Build Good Strings
Let's write a DFS solution, adding zero or one and count the good strings.
12.05.2023
medium2140. Solving Questions With Brainpower
Let's implement a bottom-up solution.
22.04.2023
hard1312. Minimum Insertion Steps to Make a String Palindrome
Just DFS and cache.
16.04.2023
hard1639. Number of Ways to Form a Target String Given a Dictionary
precompute the freq array - count of each character at each position
14.04.2023
medium516. Longest Palindromic Subsequence
For cleaner code
30.03.2023
hard87. Scramble String
A simple approach is to concatenate strings, but in Kotlin it gives TLE, so we need bottom up approach, or just operate with indices.
28.03.2023
medium983. Minimum Cost For Tickets
Let's write DFS with memoization algorithm as it is simple to understand.
27.03.2023
medium64. Minimum Path Sum
Use DFS + memo, careful with the ending condition.
26.02.2023
hard72. Edit Distance
Do DFS and use array for memoizing the result.
31.01.2023
medium1626. Best Team With No Conflicts
We can use DFS to search all the possible teams and memorize the result in dp cache.
30.01.2023
easy1137. N-th Tribonacci Number
another way is to use dp cache
22.01.2023
medium131. Palindrome Partitioning
fun partition(s: String): List> {
27.11.2022
hard446. Arithmetic Slices II - Subsequence
fun numberOfArithmeticSlices(nums: IntArray): Int {