Looking for good programming challenges?

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

All posts tagged algorithms

Get minimum time difference challenge

Problem statement Given an array of times in HH:MM format, find the minimum difference in minutes. The time is circular in nature. For example 23:52 and 00:08 have a difference of 16. Also 00:00 should be handled the same as 24:00. Solution The first key is to convert the string . . . Read more

SimpleUTF8 reverse challenge

Problem statement Consider the SimpleUTF8 format that consists of characters of the following length: – 1 byte which have the format 0XXXXXXX – 2 bytes which have the format 110XXXXX 10XXXXXX – 3 bytes which have the format 1110XXXX 10XXXXXX 10XXXXXX You will receive a byte[] str. Your task is . . . Read more

The Celebrity problem

Problem statement In a party of people, only one person is known to everyone (celebrity). That celebrity doesn’t know anyone in the party. Find the celebrity if such a person exist. Input Format The first line of the input will contain ( the number of people) and . Each of . . . Read more

Enumerate primes up to a number N

Problem statement How would enumerate all the prime numbers up to a given range? Solution There way we are going to solve it is using a well-known approach called Sieve of Eratosthenes. The approach is as follows: Assume . 1. First generate a list of integers from 2 to 30. . . . Read more

Find overlapping appointments

Problem statement Given two unsorted arrays, one with event start times and one with end times, find out if any two events overlap. Solution The key to the solution is to sort the appointments according to their start time in decreasing order, while keeping the correlation between the start and . . . Read more

Ordinal number to spreadsheet label

Problem statement Write a function that takes the ordinal number of a column in a spreadsheet and returns the label of that column.

Full code

Find missing duplicate in array

Problem statement Given an array that con­tains dupli­cates of all the num­bers except one num­ber. Find the missing number. Solution We could of course use a HashMap that maps each number to the number of occurrences. This will have a a space complexity of . A better solution is to . . . Read more

Dortmund Dilemma challenge

Problem statement Borussia Dortmund are a famous football ( soccer ) club from Germany. Apart from their fast-paced style of playing, the thing that makes them unique is the hard to pronounce names of their players ( błaszczykowski , papastathopoulos , großkreutz etc. ). The team’s coach is your friend. . . . Read more

Missing number in array [0…N]

Problem statement Given an array A = [1, 2, 3, 5, 6, 7 ] and number . This means that the array consists of the numbers from . However, as you see, is missing in . Print the missing number. Solution The solution proposed here makes use of the triangular . . . Read more

Find duplicate within k indices

Problem statement Given an array of values, design and code an algorithm that returns whether there are two duplicates within indices of each other? Do all, in running time and space. Solution The main idea is to always carry the last -visited elements with each iteration.