Hoarding programming problems for you!

Looking for good programming challenges?

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

All posts in Algorithms

Divide two integers

Problem statement Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT. Solution Obviously the naive approach to this problem would be to subtract the divisor from the dividend until the dividend becomes less than the divisor, while keeping track of how many times . . . Read more

Permutations II

Problem statement Given a list, nums, of distinct numbers, return all possible unique permutations. Sample input

Sample output

Solution In another post we showed how this problem can be solved iteratively. We can use the same technique but add a check to skip adding the number n to . . . Read more

Permutations challenge – Iterative solution

Problem statement Given a list, nums, of distinct numbers, return all possible permutations. Sample input

Sample output

Solution In another post we showed how this problem can be solved using a recursive technique by swapping. We stumbled upon a nice iterative solution that we thought might be worth . . . Read more

Permutations challenge

Problem statement Given a list, nums, of distinct numbers, return all possible permutations. Sample input

Sample output

Solution We are using a technique called permutations by swapping. Full code

Rotate Matrix / Image challenge

Problem statement You are given an 2D matrix / array representing an image. Rotate matrix by 90 degrees (clockwise) in-place. Solution We will work through the matrix layers. The layers of a matrix are illustrated below in different colours: There are a total of layers. We then iterate of the . . . Read more

Time series queries challenge

Problem statement A time series is a series of data points indexed in time order. They are commonly used in the financial world, especially in stock markets. In this challenge you are working with a time series of stock prices. You are given historical records where the stock at time . . . Read more

Longest valid parentheses challenge

Problem statement Given a string containing just the characters ( and ), find the length of the longest valid (well-formed) parentheses substring. Sample input

Sample output

Sample input 1

Sample output 1

Solution We will solve this problem using a Stack. We are going to iterate . . . Read more

Search for a range challenge

Problem statement Given an array of integers sorted in ascending order, find the starting and ending position of a given target value. If the target is not found in the array, return . Sample input

Sample output

Solution

Trapping rain water challenge

Problem statement Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. Sample input

Sample output

Solution We can solve this problem in time by iterating over the array twice. Once . . . Read more

Letter combinations of a phone number challenge

Problem statement Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone buttons) is given below. Sample input

Sample output

Solution