Algorithms

Algorithms

28 Coding Challenges in 28 Days

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

Read
Algorithms

Sliding Puzzle

A 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.

Read
Algorithms

Convex Hull

There 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.

Read
Algorithms

Huffman Coding

Given 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.

Read
Algorithms

Thinking About Partitions

Given 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.

Read
Algorithms

Querying Range Sums (2D)

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

Read
Algorithms

Querying Range Sums

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

Read
Algorithms

Longest Subarray with a Sum Constraint

Given 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