28 classic problems to test your knowledge of algorithms and data structures –– with detailed walkthroughs for each of them.

ReadA 2x3 puzzle board has tiles numbered 1 to 5 and an empty square represented by 0. A move consists of swapping 0 with an adjacent number. The puzzle is solved when [[1, 2, 3], [4, 5, 0]] is achieved. Given a puzzle configuration, return the least number of moves required to solve it.

ReadThere are multiple trees growing in a garden, each with a distinct (x, y) coordinate. You are tasked to enclose all of these trees with a single rope. The amount of rope you use should be minimised. Find the coordinates of the trees located along the rope.

ReadGiven a set of characters and their corresponding frequencies of occurrence, produce Huffman codes for each character such that the average code length is minimised. Return the average code length.

ReadGiven an array with n objects colored red, white, or blue, sort them in-place in a single pass. Objects of the same color should be adjacent to each other and the sorted colors should be in the order of red, white, and blue.

ReadDesign a matrix-like data structure that allows you to update elements and query submatrix sums efficiently.

ReadDesign an array-like data structure that allows you to update elements and query subarray sums efficiently.

ReadGiven an array of numbers A and a key k, find the length of the longest subarray whose sum is less than or equal to k.

Read