Prefix Sum Algorithm: Range Sums in O(1)
Prefix sum is a technique used to calculate the sum of elements in a given range in constant time.
Prefix sum is a technique used to calculate the sum of elements in a given range in constant time.
Timus problem 1224 Spiral: count the turns a robot makes to visit every cell of an N x M matrix, with a look at the pattern on small matrices.
How depth-first search (DFS) explores a graph branch by branch, tracks visited nodes, and backtracks, with a recursive implementation in Python.
Detect a cycle in a linked list with Floyd's tortoise and hare algorithm: slow and fast pointers, step-by-step logic, code, and O(n) time, O(1) space.
Backtracking is a general algorithm for finding all (or some) solutions to computational problems, especially in combinatorial optimization.
Find the maximum sum contiguous subarray in O(n) with Kadane's algorithm: why the naive O(n^2) approach is slow, how the algorithm works, and code.
What combinations are and how to compute them: the binomial coefficient C(n, k), combinations vs permutations, and Python code with and without itertools.
How to generate all permutations of a set: the P(n, r) formula, a recursive algorithm, and an in-place backtracking implementation in Python.