Looking for good programming challenges?

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

All posts tagged algorithms

Write a method to set all bits between i and j in N equal to M

Problem statement You are given two 32-bit numbers, and , and two bit positions, and . Write a method to set all bits between and in equal to (e g , becomes a substring of located at and starting at ) Example Input: , , , Output: Solution

Find the second smallest integer in array

Problem statement Given an array of integers, find the second smallest integer in that array. Solution

Count ways to reach the n stair

Problem statement There are stairs, a person standing at the bottom wants to reach the top. The person can climb either stair or stairs at a time. Count the number of ways, the person can reach the top. Solution We can solve this problem recursively. If the person were to . . . Read more

Given a linked list, determine if it has a cycle in it

Problem statement Given a linked list, determine if it has a cycle in it. Solution For the solution we are going to use a technique known as the two-pointer technique. That is we will involve two pointers: one slow-runner and the other fast-runner. The slow-runner will move forward 1 list . . . Read more

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