Looking for good programming challenges?

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

All posts in Algorithms

Minimum Swaps Challenge

Problem Statement You are given an unordered array consisting of consecutive integers without any duplicates. You are allowed to swap any two elements. You need to find the minimum number of swaps required to sort the array in ascending order. For example, given the array we perform the following steps: . . . Read more

Counting Valleys Challenge

Problem Statement Gary is an avid hiker. He tracks his hikes meticulously, paying close attention to small details like topography. During his last hike he took exactly steps. For every step he took, he noted if it was an uphill, , or a downhill, step. Gary’s hikes start and end . . . Read more

Stack with min() operation

Problem Statement Create a stack data structure that supports the following operations as efficiently as possible: Push, which adds a new element atop the stack, Pop, which removes the top element of the stack, Find-Min, which returns (but does not remove) the smallest element of the stack Full Code package . . . Read more

Calculate the number of ways of representing n cents

Problem Statement Given an infinite number of quarters (25 cents), dimes (10 cents), nickels (5 cents) and pennies (1 cent), write code to calculate the number of ways of representing n cents Solution This is a recursive problem, so let’s figure out how to do makeChange(n) using prior solutions (i . . . Read more

Find the second smallest integer in array

Problem statement Given an array of integers, find the second smallest integer in that array. Solution public class SecondSmallestInteger { public static int solve(int[] arr) { int smallest = Integer.MAX_VALUE; int secondSmallest = Integer.MAX_VALUE; ; for (int i = 0; i < arr.length; i++) { if (arr[i] < smallest) { . . . Read more