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

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

### Search in rotated sorted array challenge

Problem statement Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., might become ). You are given a target value to search. If found in the array return its index, otherwise return . You may assume no duplicate exists in the array. . . . Read more

### Zigzag conversion challenge

Problem statement The string PAYPALISHIRING is written in a zigzag pattern on a given number of rows like this:

And then read line by line: PAHNAPLSIIGYIR. Write the code that will take a string and make this conversion given a number of rows: Sample input

Sample output

### Next permutation challenge

Problem statement Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order). The replacement must be in-place, do not allocate extra memory. Here are some examples. . . . Read more

### Merge k sorted linked lists and return it as one sorted list

Problem statement Merge k sorted linked lists and return it as one sorted list. Solution We reduce the problem to the merging of two linked lists problem. This can be done in time and space. So we first write out the function to merge two sorted lists:

We can . . . Read more

### Combination sum challenge

Problem statement Given a set of candidate numbers (without duplicates) and a target number , find all unique combinations in where the candidate numbers sums to . The same repeated number may be chosen from unlimited number of times. Note: All numbers (including target) will be positive integers. The solution . . . Read more

### Remove Nth node from end of list

Problem statement Given a linked list:

remove the node from the end of list and return its head. Sample input

Sample output

Note: will always be valid. Solution For this we will use a two pointer technique. That is, we will iterate over our list using two . . . Read more

### 3Sum challenge

Problem statement Given an array of integers, are there elements in such that ? Find all unique triplets in the array which gives the sum of zero. Note: The solution set must not contain duplicate triplets. For example, given array , A solution set is: Solution The idea behind the . . . Read more

### Generate parentheses challenge

Problem statement Given pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given , a solution set is:

Solution