Looking for good programming challenges?

Use the search below to find our solutions for selected questions!

All posts in Algorithms

Bogosort challenge

Problem statement Logan is cleaning his apartment. In particular, he must sort his old favorite sequence, , of positive integers in nondecreasing order. He’s tired from a long day, so he invented an easy way (in his opinion) to do this job. His algorithm can be described by the following . . . Read more

Buy and sell stock once challenge

Problem statement Write a program that takes an array denoting the daily stock price, and returns the maximum profit that could be made by buying and then selling one share of stock. Solution

Cavity Map challenge

Problem statement You are given a square map of size . Each cell of the map has a value denoting its depth. We will call a cell of the map a cavity if and only if this cell is not on the border of the map and each cell adjacent . . . Read more

Misere Nim challenge

Problem statement Two people are playing game of Misère Nim. The basic rules for this game are as follows: The game starts with piles of stones indexed from to . Each pile (where ) has stones. The players move in alternating turns. During each move, the current player must remove . . . Read more

Next word

Problem statement Given a word , consisting of characters a-z, A-Z and 0-9, compute the next lexicographical word , with 0-9 < A-Z < a-z. Sample Input

Output

Solution

Notebook file https://github.com/lucaslouca/coding-problems/tree/master/python/NextWord

Maximum Perimeter Triangle challenge

Problem statement Given sticks of lengths , use of the sticks to construct a non-degenerate triangle with the maximum possible perimeter. Then print the lengths of its sides as space-separated integers in non-decreasing order. If there are several valid triangles having the maximum perimeter: Choose the one with the longest . . . Read more

Common Child challenge

Problem statement Given two strings and of equal length, what’s the longest string () that can be constructed such that it is a child of both? A string is said to be a child of a string if can be formed by deleting or more characters from . For example, . . . Read more

Exponentiation by squaring

This is a rather short post. in which I explain how to we can implement a fast pow function to raise a number to the power of . A rather naive approach would be to do the following:

This is ok, but the algorithm has a running time of . . . Read more

Gridwalking challenge

Problem statement You are situated in an dimensional grid at position . The dimensions of the grid are In one step, you can walk one step ahead or behind in any one of the dimensions. (So there are always possible different moves). In how many ways can you take steps . . . Read more

Count-and-say challenge

Problem statement The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, … 1 is read off as one 1 or 11. 11 is read off as two 1s or 21. 21 is read off as one 2, then one 1 or 1211. Given . . . Read more