### Looking for good programming challenges?

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

# All posts in Algorithms

### 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

### Given a matrix in which each row and each column is sorted, write a method to find an element in it.

Problem statement Given a matrix in which each row and each column is sorted, write a method to find an element in it. Solution Assumptions: 1. Rows are sorted left to right in ascending order. Columns are sorted top to bottom in ascending order. 2. Matrix is of size . . . . 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

### Implement an algorithm to print all valid (e g , properly opened and closed) combinations of n-pairs of parentheses

Problem Statement Implement an algorithm to print all valid (e g , properly opened and closed) combinations of n-pairs of parentheses Example Input: 3 (e g , 3 pairs of parentheses) Output: ()()(), ()(()), (())(), ((())) Solution

### Write a method to compute all permutations of a string

Problem Statement Write a method to compute all permutations of a string Solution Let’s assume a given string represented by the letters To permute set , we can select the first character, , permute the remainder of the string to get a new list Then, with that new list, we . . . Read more

### 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

### Given a sorted (increasing order) array, write an algorithm to create a binary tree with minimal height

Problem Statement Given a sorted (increasing order) array, write an algorithm to create a binary tree with minimal height. Solution We will try to create a binary tree such that for each node, the number of nodes in the left subtree and the right subtree are equal, if possible Algorithm: . . . 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

### 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

### 5 Great Books For Software Engineering Interview Preparation

Over the last few years I have applied and interviewed at a number of tech firms such as Google, Yelp, Microsoft, Amazon, Adobe and other big names. I have received offers from Palantir, Workday, Flixbus, etc. In order to be successful during those interviews (but also as an engineer in . . . Read more