KatInterview

Topic

Dynamic Programming interview problems

States, transitions and memoization on sequences and grids. 137 original problems, each with hidden test cases you can run in the browser.

Problems137

5 easy96 medium36 hard

Showing 31–60 of 137 results

  • Compute the exact probability of wealth hitting zero or below at any step during a finite sequence of random dice rolls.

    Auto-gradeddynamic-programmingmath-bitsstatistics
  • Choose one of three item types each day with no type repeated on adjacent days, minimizing total cost and returning the unique optimal sequence of choices.

    Auto-gradeddynamic-programmingpath-reconstructionpaint-house
  • Decide whether a string can become a palindrome after removing no more than k characters, testing interval dynamic programming and palindromic subsequence reasoning.

    Auto-gradeddynamic-programmingpalindromestringssubsequence
  • Find the number of unique sequences of steps to reach a target using 1-unit steps or prime steps ending in digit 3.

    Auto-gradeddynamic-programmingmathsievemodular-arithmetic
  • Match each point in one list to a different point in a larger list so the total Manhattan distance is minimal, which suits a bitmask DP given the small limits.

    Auto-gradedbitmask-dpassignment-problemmanhattan-distance
  • Enumerate all operator and bracket choices over an ordered list of numbers and return the ASCII-smallest canonical expression that evaluates to the target, or an empty string.

    Auto-gradedrecursioninterval-dpexpression-treesmemoization
  • Solve the 0/1 knapsack problem with optimal item selection, optimize its space complexity, and extend the solution to bounded knapsacks efficiently.

    Model answerdynamic-programmingarrayssliding-windowknapsack
  • Decide whether an undirected graph of at most 20 vertices has a simple path through every vertex, which is best solved with a bitmask DP over visited subsets.

    Auto-gradedbitmask-dpgraphhamiltonian-pathsubsets
  • Decide whether a pattern containing '?' and '*' wildcards matches an entire string, testing dynamic programming or greedy two-pointer matching with backtracking.

    Auto-gradedstringswildcard-matchingdynamic-programminggreedy
  • Find the minimum combined count of paid and received coins to settle a precise target value using dynamic programming.

    Auto-gradeddynamic-programmingarrays
  • Color a row of posts from a cost table so no two neighbors match, minimizing total cost, using memoized recursion and a space-optimized bottom-up DP, and recover one optimal coloring.

    Model answerdynamic-programmingmemoizationspace-optimizationreconstruction
  • Count the ways to give each person a distinct acceptable item and find the best total value, using a bitmask DP over people or bounded backtracking.

    Auto-gradedbitmask-dpcountingbacktrackingassignment
  • Determine if a given string can be converted into a palindrome by removing at most k characters.

    Auto-gradeddynamic-programmingstringsbit-manipulation
  • Find all strings in a list that can be constructed by concatenating two or more smaller strings from the same list.

    Model answerstringsdynamic-programmingtriehash-table
  • Find the maximum weight independent set for both a linear sequence and a binary tree network under non-adjacency constraints.

    Auto-gradeddynamic-programmingtrees-graphsarrays
  • Compute the minimum total cost of a route through a rectangular cost grid using only right and down moves, which tests 2D dynamic programming with a space optimization.

    Auto-gradeddynamic-programminggridmatrixoptimization
  • Find the minimum combination of reusable containers to reach an exact target total volume, or return None if impossible.

    Auto-gradeddynamic-programmingunbounded-knapsackbacktracking
  • Find the maximum total node sum from a binary tree represented as a level-order list such that no two selected nodes share a parent-child edge.

    Auto-gradedtrees-graphsdynamic-programmingarrays
  • Decide whether a subsequence of positive integers, joined by + and * and evaluated strictly left to right, can equal a target, and produce one valid expression.

    Model answerdynamic-programmingbacktrackingpruningreverse-search
  • Count valid grid paths composed of horizontal and vertical steps such that no direction is repeated three times in a row.

    Auto-gradeddynamic-programminggridcombinatoricsmemoization
  • Enumerate every distinct selection of list elements, each used at most once, that sums to a target, with negatives, zeros and duplicates allowed. Tests backtracking over value counts.

    Auto-gradedbacktrackingsubset-sumduplicatesenumeration
  • Delete any elements from an array so the most remaining values equal their new 1-based position. Reduce it to a longest-chain problem solved in O(n log n).

    Model answerdynamic-programminglongest-increasing-subsequencebinary-searchsubsequence
  • Design a deterministic per-tick controller for a thruster-driven drone navigating procedurally generated obstacle canyons using lookahead simulation.

    Model answerdynamic-programminglookahead-searchsimulationmemoization
  • Find the largest total achievable by a non-empty run of adjacent integers, handling all-negative inputs and large sums, in one pass with constant extra space.

    Auto-gradedkadanesubarraydynamic-programmingarrays
  • Find the most disjoint three-card groups that each sum to 15, using memoized search over value counts because greedy choices can block better groupings.

    Auto-gradedmemoizationrecursioncombinatoricsstate-compression
  • Maximize profit from daily share prices using at most k non-overlapping buy-then-sell trades, testing state-based dynamic programming and handling a trade limit that never binds.

    Auto-gradeddynamic-programmingarraysstock-tradingstate-machine
  • Count integers in a huge range grouped by digit sum and return the largest group size, which needs a digit DP with prefix-count subtraction rather than enumeration.

    Auto-gradeddigit-dpcountingrange-queriesmath
  • Find the longest block of consecutive values common to two integer lists, and report its length and the smallest pair of start positions, using dynamic programming over suffix matches.

    Auto-gradeddynamic-programmingarrayssubarraytie-breaking
  • Find the longest chain of orthogonally adjacent cells with strictly increasing values in a 2D grid, testing DAG longest-path DP, memoization, and avoiding deep recursion.

    Auto-gradeddynamic-programminggraphdfsmemoization
  • Interleave two letter strings while keeping each one's order, minimizing out-of-order pairs; tests 2D prefix DP with O(1) transition costs from alphabet-count tables.

    Auto-gradeddynamic-programmingstringsprefix-countsinterleaving

More topics