category: dp

source: internal

difficulty: easy

statement: Return the n-th Fibonacci number where fib(0)=0, fib(1)=1. Implement a function fib(n: int) -> int. Use O(n) time and O(1) space.

primary_function: fib

selection_rationale: Canonical DP recurrence; tests base cases and iterative form.

description: n=0 base case

kind: deterministic

description: n=1 base case

description: small

description: medium

description: large


statement: You are climbing a staircase. It takes n steps to reach the top. Each time you can climb 1 or 2 steps. Return the number of distinct ways. Implement climbStairs(n: int) -> int.

primary_function: climbStairs

selection_rationale: Fibonacci-equivalent DP under a different name; tests recurrence recognition.


statement: Given coins (list of int) and an integer amount, return the minimum number of coins to make ``amount`` or -1 if impossible. Implement coinChange(coins, amount).

primary_function: coinChange

selection_rationale: Classic unbounded-knapsack DP; tests unreachable-state handling.

description: standard

description: unreachable

description: larger

description: non-trivial


statement: Return the length of the longest common subsequence of two strings a and b. Implement longestCommonSubsequence(a: str, b: str) -> int.

primary_function: longestCommonSubsequence

selection_rationale: Two-string DP; common LLM failure: confusing subsequence with substring.

args: abcde ace

description: standard

args: abc abc

description: identical

args: abc def

description: disjoint

description: empty

args: AGGTAB GXTXAYB

description: textbook


statement: Given an array nums of non-negative ints, return the max sum you can collect without picking adjacent elements. Implement rob(nums: list[int]) -> int.

primary_function: rob

selection_rationale: 1D DP with adjacency constraint; tests linear scan formulation.

description: standard

description: standard

description: empty

description: single

description: adjacent equal


statement: Given an m x n grid of non-negative ints, return the minimum path sum from top-left to bottom-right moving only right or down. Implement minPathSum(grid: list[list[int]]) -> int.

primary_function: minPathSum

selection_rationale: 2D DP on a grid; tests indexing and boundary handling.

description: standard

description: rectangle

description: single cell

description: uniform


statement: Given an integer array nums, return the length of the longest strictly increasing subsequence. Implement lengthOfLIS(nums) -> int.

primary_function: lengthOfLIS

selection_rationale: O(n log n) preferred; tests common O(n^2) baseline against optimal.

description: standard

description: repeats

description: all equal

description: empty

description: strictly increasing


statement: Given prices[i] = price of a rod of length i+1 and an integer n, return the max obtainable revenue by cutting the rod of length n. Implement rodCutting(prices, n).

primary_function: rodCutting

selection_rationale: Unbounded knapsack pattern with index off-by-one risk.

description: textbook

description: alt prices

description: single length

description: small


statement: Given an array p of length n where matrix A_i has dimensions p[i-1] x p[i], return the minimum number of scalar multiplications. Implement matrixChainOrder(p: list[int]) -> int.

primary_function: matrixChainOrder

selection_rationale: Interval DP; tests nested-loop formulation.

description: 3 matrices

description: textbook 1

description: 2 matrices

description: textbook 2

description: small


source: apps-introductory

statement: Given a list of positive ints nums and a target T, return True iff some subset of nums sums to T. Implement subsetSum(nums, target) -> bool.

primary_function: subsetSum

selection_rationale: APPS-style decision DP; tests boolean DP table.

expected: true

description: standard

description: standard

expected: false

description: impossible

description: empty target 0

description: single hit


category: graph

statement: Given the number of tasks N and a list of dependency pairs prerequisites where [a, b] means b must finish before a, return any valid order or [] if impossible. Implement findOrder(numCourses: int, prerequisites: list[list[int]]) -> list[int].

primary_function: findOrder

selection_rationale: Cycle detection + topo order; common LLM failure: missing cycle check.

description: linear chain

description: cycle

description: single

expected: "any valid order"

description: branching

description: complex cycle


statement: Given an undirected graph as an adjacency list adj (list of list of int), return True iff it contains a cycle. Implement hasCycle(adj: list[list[int]]) -> bool.

primary_function: hasCycle

selection_rationale: Undirected cycle detection (parent-tracking DFS).

description: path

description: triangle

description: single

description: two paths

description: square


statement: Given an adjacency list adj and a start node s, return the BFS visit order from s (ties broken by neighbour list order). Implement bfs(adj: list[list[int]], s: int) -> list[int].

primary_function: bfs

selection_rationale: BFS basics; tests queue usage and visited set.

description: tree

description: single

description: edge

description: triangle

description: isolated


statement: Given an adjacency list adj and a start node s, return the DFS preorder visit order (recursive, neighbour order respected). Implement dfs(adj: list[list[int]], s: int) -> list[int].

primary_function: dfs

selection_rationale: DFS basics; tests recursion + visited.

description: tree

description: single

description: edge

description: triangle

description: isolated start


statement: Given a weighted graph as adj where adj[u] = list of (v, w), and a source s, return a list dist of length n with shortest distances from s (use float('inf') for unreachable). Implement dijkstra(adj: list[list[tuple[int, int]]], s: int) -> list[float].

primary_function: dijkstra

selection_rationale: Priority queue + relaxation; common LLM failure: missing heap usage.

description: textbook

description: single

description: edge

description: line

description: relax


statement: Given n nodes and a list of weighted edges (u, v, w) (directed), return shortest distances from source s, or None if a negative cycle is reachable. Implement bellmanFord(n, edges, s) -> list | None.

primary_function: bellmanFord

selection_rationale: Tests negative-cycle detection.

description: neg cycle

description: single edge

description: single node

description: line


statement: Given an adjacency list adj of an undirected graph, return the number of connected components. Implement countComponents(adj) -> int.

primary_function: countComponents

selection_rationale: Tests union-find or DFS sweep.


statement: Given a directed graph as adjacency list adj, return the number of strongly connected components. Implement countSCC(adj) -> int.

primary_function: countSCC

selection_rationale: Kosaraju / Tarjan; tests two-pass DFS.

description: single SCC

description: path 3

description: cycle 2

description: two cycles

description: single


statement: Given an adjacency list adj and source s, return shortest hop counts from s. Use -1 for unreachable. Implement shortestHops(adj, s) -> list[int].

primary_function: shortestHops

selection_rationale: Tests BFS distance variant.

description: unreachable


statement: Given an m x n binary grid where 0 is passable and 1 is a wall, return the length of the shortest path from (0,0) to (m-1,n-1) using 4-neighbour moves, or -1 if unreachable. Implement shortestPath(grid) -> int.

primary_function: shortestPath

selection_rationale: APPS-style grid BFS; tests boundary + visited.


category: ds

statement: Implement an LRU cache class LRUCache with __init__(self, capacity: int), get(key) -> int (returns -1 if absent), and put(key, value). Capacity is a positive int.

primary_function: LRUCache

selection_rationale: Class with O(1) get/put; common LLM failure: incorrect eviction.

description: textbook

description: capacity 1

description: evict


statement: Implement a stack class MinStack supporting push(x), pop(), top(), getMin() all in O(1).

primary_function: MinStack

selection_rationale: Tests auxiliary-stack pattern.

call: [(lambda s: ([s.push(-2), s.push(0), s.push(-3), s.getMin(), s.pop(), s.top(), s.getMin()]))(MinStack())]

description: textbook

call: [(lambda s: ([s.push(1), s.push(2), s.getMin(), s.pop(), s.getMin()]))(MinStack())]

description: ascending

call: [(lambda s: ([s.push(3), s.push(1), s.push(1), s.getMin(), s.pop(), s.getMin()]))(MinStack())]

description: duplicates


statement: Implement class MyStack with push(x), pop(), top(), empty() using only queues.

primary_function: MyStack

selection_rationale: Tests queue-based simulation of stack semantics.

call: [(lambda s: ([s.push(1), s.push(2), s.top(), s.pop(), s.empty()]))(MyStack())]

description: basic

call: [(lambda s: ([s.push(1), s.pop(), s.empty()]))(MyStack())]

description: single

call: [(lambda s: ([s.push(1), s.push(2), s.push(3), s.pop(), s.top()]))(MyStack())]

description: three elems


statement: Define class ListNode(self, val=0, next=None) and a function reverseList(head: ListNode | None) -> ListNode | None that reverses the list. Also provide a helper to_list(head) -> list[int] that materializes a linked list.

primary_function: reverseList

selection_rationale: Tests pointer-rewiring; LLM failure: lost head pointer.

description: three cases


statement: Define class TreeNode(self, val=0, left=None, right=None) and a function inorder(root) -> list[int] that returns the inorder traversal.

primary_function: inorder

selection_rationale: Tests recursive traversal.

call: (lambda: (inorder(None),inorder(TreeNode(1)),inorder(TreeNode(1, TreeNode(2), TreeNode(3)))))()

description: three trees


statement: Implement class PQ with push(x), pop() -> smallest, top() -> smallest, empty().

primary_function: PQ

selection_rationale: Min-heap semantics.

call: (lambda q: ([q.push(3), q.push(1), q.push(2), q.top(), q.pop(), q.pop(), q.empty()]))(PQ())

description: basic

call: (lambda q: q.empty())(PQ())

description: empty


statement: Implement heapify(arr: list[int]) -> None that converts arr into a min-heap in-place.

primary_function: heapify

selection_rationale: Tests in-place heap construction.

call: (lambda a: (heapify(a), a == sorted(a) or all(a[i] <= a[2*i+1] for i in range(len(a)) if 2*i+1 < len(a)) and all(a[i] <= a[2*i+2] for i in range(len(a)) if 2*i+2 < len(a))))([4,1,3,2,16,9,10,14,8,7])

description: textbook


statement: Implement class AVL with insert(key) and inorder() -> list[int] that returns the sorted keys after insertions while maintaining AVL balance.

primary_function: AVL

selection_rationale: Balanced BST; tests rotation correctness.

description: balanced inorder


statement: Given n vertices and a list of undirected edges, return an adjacency list (list of sorted neighbour lists). Implement adjList(n, edges).

primary_function: adjList

selection_rationale: Tests data-structure assembly.


statement: Given a string of '()[]{}', return True iff brackets close in correct order. Implement isValid(s: str) -> bool.

primary_function: isValid

selection_rationale: APPS-style stack; classic textbook.