08 2017 档案
摘要:Given an array of length n that stores a stock's price in n consecutive days, Buy/Sell stock with at most K transactions to maximize profit. You must
阅读全文
摘要:Implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more of the preceding elemen
阅读全文
摘要:Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. '*' Matches any sequence of characters (including
阅读全文
摘要:Same Problem Link. [LintCode] Regular Expression Matching
阅读全文
摘要:Same Problem Link. [LintCode] Wildcard Matching
阅读全文
摘要:Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloon
阅读全文
摘要:N pots, each with some number of gold coins, are arranged in a line. You are playing a game against another player. You take turns picking a pot of go
阅读全文
摘要:Given a string s, cut s into some substrings such that every substring is a palindrome. Return the minimum cuts needed for a palindrome partitioning o
阅读全文
摘要:Given a string and a dictionary, return true if the string can be split into multiple words such that each word is in dictionary. If not return false.
阅读全文
摘要:Given a 2 dimensional matrix, find minimum cost path to reach bottom right from top left provided you can only from down and right. For a 5 * 5 matrix
阅读全文
摘要:Given a string, how many minimum splits would it take so that each partition after split is a palindrome. Same Problem Link [LintCode] Palindrome Part
阅读全文
摘要:Given two strings and operations edit, delete and add, how many minimum operations would it take to convert one string to another string. Same Problem
阅读全文
摘要:Given a sequence of words, and a limit on the number of characters that can be put in one line(line width). Put line breaks in the given sequence such
阅读全文
摘要:Given boxes of different dimensions, stack them on top of each other to get maximum height such that box on top has strictly less length and width tha
阅读全文
摘要:Given an array, find maximum sum increasing subsequence in this array. Solution 1. Recursion For arr[0....n], the max sum increasing subsequence can b
阅读全文
摘要:Given a string, find longest palindromic subsequence in this string. lps[start, end] = lps[start + 1, end - 1] + 2, if s.charAt(start) == s.charAt(end
阅读全文
摘要:Given an array, find the longest increasing subsequence in this array. The same problem link. [LintCode] Longest Increasing Subsequence Related Proble
阅读全文
摘要:Given an array, find minimum number to jumps to reach end of array, given you can jump at max as much as value at position in array. The same problem
阅读全文
摘要:Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is formed from t
阅读全文
摘要:Given three strings, return true if third string is interleaving of first and second string. By running some examples, it seems that as long as s1.len
阅读全文
摘要:Given a matrix of 0s and 1s. Find biggest sub-square matrix entirely of 1s in this matrix. The same problem link is as follows. Maximal Square
阅读全文
摘要:Given a binary search tree with the following tree node definition. next points to a node's inorder successor. Populate inorder successor for all node
阅读全文
摘要:Given a binary tree, get all nodes that don't have sibling node, excluding the root node. Level order and pre order solutions.
阅读全文
摘要:Given an array of positive number, find maximum sum subsequence such that elements in this subsequence are not adjacent to each other. Recursive formu
阅读全文
摘要:Find longest bitonic subsequence in given array. Bitonic subsequence first increases then decreases. Same problem link Longest Bitonic Subsequence
阅读全文
摘要:Given a staircase and give you can take 1 or 2 steps at a time, how many ways you can reach nth step. Same problem link. Climbing Stairs
阅读全文
摘要:Given a 2D immutable array, Write an efficient program to support any given sub-rectangle sum query in this 2D matrix. A simple solution is to add eac
阅读全文
摘要:Find Maximum Number that can be formed using all digits in the given integer. Solution 1. O(n * log n) runtime, O(n) space using sorting A simple solu
阅读全文
摘要:Given an unsorted array of integers, sort this array using tree sort. 1. Create a binary search tree by inserting array elements. 2. Perform in order
阅读全文
摘要:Given Inorder and Preorder traversals of a binary tree, print Postorder traversal. Example: A naive solution is to first construct the given tree, the
阅读全文
摘要:Given a 2D binary matrix filled with 0's and 1's, find the largest square which diagonal is all 1 and others is 0. Only consider the main diagonal sit
阅读全文
摘要:Given a 2D matrix where every element is either ‘O’ or ‘X’, find the largest subsquare surrounded by ‘X’. Examples: Solution 1. O(N^4) runtime. Consid
阅读全文
摘要:Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area. For example, given the following mat
阅读全文
摘要:Given a number n, find the total number of numbers from 0 to 2^n - 1 which do not have consecutive 1s in their binary representation. Solution. This p
阅读全文
摘要:Give a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from root node down to the nearest leaf n
阅读全文
摘要:Given n which is total number of keys in BST, how many BSTs can be formed with n keys. Solution 1. Recursion Solution 2. Dynamic Programming
阅读全文
摘要:Given a 2 dimensional matrix, how many ways you can reach bottom right from top left provided you can only move down and right.
阅读全文
摘要:Count Number of Binary Tree Possible given Preorder Sequence. For example, given preorder sequence of {10, 11, 9, 12, 13, 14}, the total possible numb
阅读全文
摘要:Write a function to print spiral order traversal of a binary tree. For below tree, function should print 1, 2, 3, 4, 5, 6, 7. Solution. For a normal l
阅读全文
摘要:Given coins of certain denominations and a total, how many ways these coins can be combined to get the total. Dynamic Programming solution State: T[i]
阅读全文
摘要:Given coins of certain denominations and a total, how many minimum coins would you need to make this total? Dynamic Programming solution State: T[i][j
阅读全文
摘要:Given some number of floors and some number of eggs, what is the minimum number of attempts it will take to find out from which floor egg will break.
阅读全文
摘要:Given certain jobs with start and end time and amount you make on finishing the job, find the maximum value you can make by scheduling jobs in non-ove
阅读全文
摘要:Given a rod of length and prices at which different length of this rod can sell, how do you cut this rod to maximize profit. Solution. Dynamic Program
阅读全文
摘要:Given two strings, find longest common substring between them. Solution 1. Brute force search, O(n^2 * m), O(1) memory Algorithm. O(n^2) runtime to fi
阅读全文
摘要:Given an array with n distinct elements, convert the given array to a form where all elements are in range from 0 to n-1. The order of elements is sam
阅读全文
摘要:Given a sorted array, this array is rotated by some unknown times. Find if there is a pair in this array that sums to a given value. Solution 1. O(n *
阅读全文
摘要:Given keys and frequency at which these keys are searched, how would you create a binary search tree from these keys such that the cost of searching i
阅读全文
摘要:Write a program to delete a tree. Solution. To delete all tree nodes, we need to set all non-leaf nodes' children nodes to null. So for a given non-le
阅读全文
摘要:Write a function to detect if two trees are isomorphic. Two trees are called isomorphic if one of them can be obtained from other by a series of flips
阅读全文
摘要:Given a binary tree, where every node value is a number . Find the sum of all the numbers which are formed from root to leaf paths. For example consid
阅读全文
摘要:Given an array, find the minimum length unsorted subarray. After soring this unsorted subarray, the whole array is sorted. Example, if the input array
阅读全文
摘要:Given an array of integers, write a program that cyclically rotates the array by one. Example: given {1,2,3,4,5}, your program should rotate the array
阅读全文
摘要:Given a binary tree, convert it to its mirror tree. Mirror of a binary tree T is another binary tree M with the left and right children of all non-lea
阅读全文
摘要:Given a singly linked list whose nodes contain an integer as their keys. All keys are distinct. Swap the node that has key x with the node that has ke
阅读全文
摘要:Given a set of distinct integers, return all possible subsets. Notice Elements in a subset must be in non-descending order. The solution set must not
阅读全文
摘要:Given a set of non negative integers and a target value, find if there exists a subset in the given set whose sum is target. Solution 1. Enumerate all
阅读全文
摘要:Given an array, write a program to generate a random permuation of array elements. This question is also asked as "shuffle a deck of cards" or "random
阅读全文
摘要:Given a binary tree, find the maximum depth or height of this tree. Solution 1. In order traversal to count the maximum depth 1 import java.util.Linke
阅读全文
摘要:Given a BST whose keys are integers. Find the inorder successor and predecessor of a given key. In case the given key is not found in the BST, return
阅读全文
摘要:Given some matrices, in what order you would multiply them to minimize cost of multiplication. The following problem formulation is extracted from thi
阅读全文
摘要:Given a sorted array. Write a program that creates a Balanced Binary Search Tree using array elements. If there are n elements in array, then floor(n/
阅读全文
摘要:Given a Binary Tree, Print the corner nodes at each level. The node at the leftmost and the node at the rightmost. For example, output for following i
阅读全文
摘要:Given two strings, find the longest common subsequence (LCS). Your code should return the length of LCS. Given two strings, find the longest common su
阅读全文
摘要:Given a string s and a dictionary of words dict, determine if s can be break into a space-separated sequence of one or more dictionary words. Example
阅读全文
摘要:A Maze is given as N*N binary matrix of blocks where source block is the upper left most block i.e., maze[0][0] and destination block is lower rightmo
阅读全文
摘要:Give a number n, check if it is a fibonacci number. Solution 1. Generate a sequence of fibonacci number until we have a fibonacci number that is eithe
阅读全文

浙公网安备 33010602011771号