12 2014 档案
摘要:Given an array of integers, find the subarray with smallest sum.Return the sum of the subarray.NoteThe subarray should contain at least one integer.Ex...
阅读全文
摘要:Given a string which contains only letters. Sort it by lower case first and upper case second.NoteIt's not necessary to keep the original order of low...
阅读全文
摘要:Given two strings, find the longest comment subsequence (LCS).Your code should return the length of LCS.ExampleFor "ABCD" and "EDCA", the LCS is "A" (...
阅读全文
摘要:Given two strings, find the longest common substring.Return the length of it.NoteThe characters in substring should occur continiously in original str...
阅读全文
摘要:Count the number of k's between 0 and n. k can be 0 - 9.Exampleif n=12, in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], we have FIVE 1's (1, 10, 11, 12...
阅读全文
摘要:Compare two strings A and B, determine whether A contains all of the characters in B.The characters in string A and B are all Upper Case letters.Examp...
阅读全文
摘要:For given numbers a and b in function aplusb, return the sum of them.NoteYou don't need to parse the input and output. Just calculate and return.Examp...
阅读全文
摘要:Design an iterator over a binary search tree with the following properties:Elements are visited in ascending order (i.e. an inorder traversal)next() a...
阅读全文
摘要:The code base version is an integer and start from 1 to n. One day, someone commit a bad version in the code case, so it caused itself and the followi...
阅读全文
摘要:Given a root of Binary Search Tree with unique value for each node. Remove the node with given value. If there is no such a node with given value in t...
阅读全文
摘要:Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space i...
阅读全文
摘要:Given an array ofnobjects with k different colors (numbered from 1 to k), sort them so that objects of the same color are adjacent, with the colors in...
阅读全文
摘要:Write an efficient algorithm that searches for a value in an m x n matrix, return the occurrence of it.This matrix has the following properties: * In...
阅读全文
摘要:Given a list of integers, which denote a permutation.Find the previous permutation in ascending order.NoteThe list may contains duplicate integers.Exa...
阅读全文
摘要:Given an integer array, heapify it into a min-heap array.For a heap array A, A[0] is the root of heap, and for each A[i], A[i * 2 + 1] is the left chi...
阅读全文
摘要:Numbers keep coming, return the median of numbers at every time a new number added.ExampleFor numbers coming list: [1, 2, 3, 4, 5], return [1, 1, 2, 2...
阅读全文
摘要:Given a sequence of integers, find the longest increasing subsequence (LIS). You code should return the length of the LIS. Example For [5, 4, 1, 2, 3]
阅读全文
摘要:Find K-th largest element in an array.NoteYou can swap elements in the arrayExampleIn array [9,3,2,4,8], the 3th largest element is 4ChallengeO(n) tim...
阅读全文
摘要:Given an array of integers and a number k, the majority number is the number that occurs more than 1/k of the size of the array. Find it. Note There i
阅读全文
摘要:Given an array of integers, the majority number is the number that occurs more than 1/3 of the size of the array.Find it.NoteThere is only one majorit...
阅读全文
摘要:Given an array of integers, the majority number is the number that occurs more than half of the size of the array. Find it.ExampleFor [1, 1, 1, 1, 2, ...
阅读全文
摘要:Given an integer array, find a subarray where the sum of numbers is zero. Your code should return the index of the first number and the index of the l...
阅读全文
摘要:Given an array "nums" of integers and an int "k", Partition the array (i.e move the elements in "nums") such that, * All elements = k are moved to th...
阅读全文
摘要:Using O(1) time to check whether an integer n is a power of 2.ExampleFor n=4, return trueFor n=5, return falseChallengeO(1) timeAnalysis:Use bit manip...
阅读全文
摘要:Given an array with integers.Find two non-overlapping subarrays A and B, which |SUM(A) - SUM(B)| is the largest.Return the largest difference.NoteThe ...
阅读全文
摘要:Given an integer array, find a subarray with sum closest to zero. Return the indexes of the first number and last number.ExampleGiven [-3, 1, 1, -3, 5...
阅读全文
摘要:The size of the hash table is not determinate at the very beginning. If the total size of keys is too large (e.g. size >= capacity / 10), we should do...
阅读全文
摘要:Given an integer array with no duplicates. A max tree building on this array is defined as follow:The root is the maximum number in the arrayThe left ...
阅读全文
摘要:Given an array with positive and negative integers. Re-range it to interleaving with positive and negative integers.NoteYou are not necessary to keep ...
阅读全文
摘要:Given an directed graph, a topological order of the graph nodes is defined as follow:For each directed edge A-->B in graph, A must before B in the ord...
阅读全文
摘要:Given a string and an offset, rotate string by offset. (rotate from left to right)ExampleGiven "abcdefg"for offset=0, return "abcdefg"for offset=1, re...
阅读全文
摘要:Given an array of integers and a number k, find k non-overlapping subarrays which have the largest sum.The number in each subarray should be contiguou...
阅读全文
摘要:Given an array of integers, find two non-overlapping subarrays which have the largest sum.The number in each subarray should be contiguous.Return the ...
阅读全文
摘要:Design an algorithm to find the kth number such that the only prime factors are 3, 5, and 7. The eligible numbers are like 3, 5, 7, 9, 15 ... Example
阅读全文
摘要:Given n items with size A[i], an integer m denotes the size of a backpack. How full you can fill this backpack?NoteYou can not divide any item into sm...
阅读全文
摘要:Given a matrix of lower alphabetsand a dictionary.Find all words in the dictionary that can be found in the matrix. A word can start from any position...
阅读全文
摘要:Calculate the an% b where a, b and n are all 32bit integers.ExampleFor 231 % 3 = 2For 1001000 % 1000 = 0ChallengeO(logn)Solution: 1 class Solution { 2...
阅读全文
摘要:In data structure Hash, hash function is used to convert a string(or any other type) into an integer smaller than hash size and bigger or equal to zer...
阅读全文
摘要:Given a stringsand a dictionary of wordsdict, determine ifscan be segmented into a space-separated sequence of one or more dictionary words.ExampleGiv...
阅读全文
摘要:Given n distinct positive integers, integer k (k <= n) and a number target. Find k numbers where sum is target. Calculate how many solutions there are
阅读全文
摘要:BT(binary tree), want to find the LIS(largest independent set) of the BT. LIS: if the current node is in the set, then its children should not be in t...
阅读全文
摘要:假设你是harry potter,在grid的左上角,你现在要走到右下角,grid中有正数也有负数,遇到正数表示你的strength增加那么多,遇到负数表示strength减少那么多,在任何时刻如果你的strength小于等于0,那么你就挂了。在一开始你有一定的初始的strength,现在问这个初始...
阅读全文
摘要:Given an integer array, adjust each integers so that the difference of every adjcent integers are not greater than a given number target.If the array ...
阅读全文
摘要:Given an array, determine whether there are three elements A[i],A[j],A[k], such that A[i]A[twoLen]) return true; 9 if (twoLen!=-1 && A[i]>...
阅读全文
摘要:Given an array of integers, every element appears three times except for one. Find that single one. Note: We generalize this problem to: Given an arra
阅读全文
摘要:Given an array of integers, every element appears twice except for one. Find that single one.Analysis:Use XOR operation.Solution: 1 public class Solut...
阅读全文
摘要:There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited gas tank and it cost
阅读全文
摘要:Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be o...
阅读全文
摘要:Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractional part is repeating,...
阅读全文
摘要:Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the hist...
阅读全文
摘要:Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.Solution: 1 public class Solution { 2 ...
阅读全文
摘要:Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.A better solution: 1 /** 2 * Definition for a po...
阅读全文
摘要:There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be ...
阅读全文
摘要:Given two strings S and T, determine if they are both one edit distance apart.Analysis:Must be exactly one distance apart. Not the same.Solution: 1 pu...
阅读全文
摘要:The API: int read4(char *buf) reads 4 characters at a time from a file.The return value is the actual number of characters read. For example, it retur...
阅读全文
摘要:The API: int read4(char *buf) reads 4 characters at a time from a file.The return value is the actual number of characters read. For example, it retur...
阅读全文
摘要:Given a string, find the length of the longest substring T that contains at most 2 distinct characters.For example, Given s = “eceba”,T is "ece" which...
阅读全文
摘要:Given a sorted integer array where the range of elements are [lower, upper] inclusive, return its missing ranges. For example, given [0, 1, 3, 50, 75]
阅读全文
摘要:Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to end, such that:Only one letter can be ch...
阅读全文
摘要:Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example,Given [100, 4, 200, 1, 3, 2],The longes...
阅读全文
摘要:Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning ...
阅读全文
摘要:There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following req...
阅读全文
摘要:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy ...
阅读全文
摘要:Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such p
阅读全文
摘要:Given a binary tree, return the postorder traversal of its nodes' values. For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,...
阅读全文
摘要:Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set. get(key) - Get the...
阅读全文
摘要:A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index...
阅读全文

浙公网安备 33010602011771号