# All posts in Algorithms

Problem StatementThe figure below illustrates the first five rows of a graphic that is known as Pascal’s triangle. Each entry in each row before the last one is adjacent to one or two numbers in the lower row. It is a fact that each entry holds the sum of the . . . Read more

Problem Statement You are given a list of non-negative integers, a1, a2, …, an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose one from + and – as its new symbol. Find out how many ways to assign symbols to . . . Read more

Problem Statement You have d dice, and each die has f faces numbered 1, 2, …, f. Return the number of possible ways (out of fd total ways) modulo 10^9 + 7 to roll the dice so the sum of the face up numbers equals target. Example 1 Input: d . . . Read more

Problem Statement You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return . . . Read more

Problem Statement Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place. Example 1: Input: [ [1,1,1], [1,0,1], [1,1,1] ] Output: [ [1,0,1], [0,0,0], [1,0,1] ] Solution We will use the first cell of every row and column . . . Read more

Problem Statment Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the nodes in each of the two partitions. Example Input: head = 1->4->3->2->5->2, x . . . Read more

Problem Statement Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Input: haystack = “hello”, needle = “ll” Output: 2 Solution

Problem Statement Given an array nums and a value val, remove all instances of that value in-place and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. The order of elements can be . . . Read more

Problem StatementGiven a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. Given nums = [0,0,1,1,1,2,2,3,3,4], Your function . . . Read more

Problem Statement You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. You may assume the two numbers do not contain any . . . Read more