01 2016 档案
Leetcode: Patching Array
摘要:Given a sorted positive integer array nums and an integer n, add/patch elements to the array such that any number in range [1, n] inclusive can be for
阅读全文
Leetcode: Longest Increasing Path in a Matrix
摘要:DFS + DP: use a two dimensional matrix dp[i][j] to store the length of the longest increasing path starting at matrix[i][j] transferring function is:
阅读全文
G面经prepare: Maximum Subsequence in Another String's Order
摘要:求string str1中含有string str2 order的 subsequence 的最小长度DP做法:dp[i][j]定义为pattern对应到i位置,string对应到j位置时,shortest substring的长度,Int_Max表示不存在 1 package ShortestSu...
阅读全文
G面经prepare: Set Intersection && Set Difference
摘要:求两个sorted数组的intersection e.g. [1,2,3,4,5],[2,4,6] 结果是[2,4]difference类似merge, 分小于等于大于三种情况,然后时间O(m+n), 空间O(1) 1 package ShortestSubsequenceIncluding; 2...
阅读全文
G面经prepare: Pattern Match
摘要:设定一个pattern 把 'internationalization' 变成 'i18n', 比如word是house,pattern可以是h3e, 3se, 5, 1o1s1等,给pattern和word,判断是否match, 1 package DataStreamAverage; 2 3 ...
阅读全文
G面经prepare: Data Stream Average
摘要:给一个datastream和一个fixed window size, 让我design一个class可以完成add number还有find average in the window. 就是不能用vector得用array. 当然用queue是最好的package DataStreamAverag...
阅读全文
Summary: Final Keyword
摘要:In this tutorial we will learn the usage of final keyword. final keyword can be used along with variables, methods and classes. We will cover followin...
阅读全文
G面经prepare: Jump Game Return to Original Place
摘要:第二题 算法 给你一个arr 返回 T 或者 Farr的每个数代表从这个点开始跳几部,返回T的情况:从这个arr中任意一个数开始跳,可以在每个元素都跳到且只跳到一次的情况下返回到开始跳的元素比如[1,1,1,1,1,1] => T[0,1,1,1,1,1]=> F[7, 5, 2, 3] => F[...
阅读全文
G面经prepare: Reorder String to make duplicates not consecutive
摘要:字符串重新排列,让里面不能有相同字母在一起。比如aaabbb非法的,要让它变成ababab。给一种即可Greedy:跟FB面经Prepare task Schedule II很像,记录每个char出现次数,然后用最大堆,把剩下char里面出现次数多的优先Poll出来组建新的string如果poll出...
阅读全文
G面经prepare: Sort String Based On Another
摘要:Given a sorting order string, sort the input string based on the given sorting order string. Ex sorting order string -> dfbcae Input string -> abcdeea...
阅读全文
G面经Prepare: Valid Preorder traversal serialized String
摘要:1 求问下各位大神,怎么判断一个按照Preorder traversal serialized的binary tree的序列是否正确呢?不能deserialize成树比如2 A) 9 3 4 # # 1 # # 2 # 6 # #是对的,因为表示3 94 / ...
阅读全文
Leetcode: Range Sum Query 2D - Mutable && Summary: Binary Indexed Tree
摘要:参考:https://leetcode.com/discuss/72685/share-my-java-2-d-binary-indexed-tree-solution Build binary indexed tree takes : O(mn*logm*logn) time, both upda
阅读全文
Leetcode: Odd Even Linked List
摘要:Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the...
阅读全文
Leetcode: Count of Range Sum
摘要:Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive. Range sum S(i, j) is defined as the sum of the elem
阅读全文
Lintcode: Kth Smallest Number in Sorted Matrix
摘要:Find the kth smallest number in at row and column sorted matrix.ExampleGiven k =4and a matrix:[ [1 ,5 ,7], [3 ,7 ,8], [4 ,8 ,9],]return5ChallengeKL...
阅读全文
G面经prepare: Chucked Palindrome
摘要:给定一个字符串,找出最多有多少个chunked palindrome,正常的palindrome是abccba, chunked palindrome的定义是:比如volvo, 可以把vo划分在一起,(vo) (l) (vo),那么它是个palindrome。求实现返回最大的chunk 数量。比如...
阅读全文
G面经prepare: BuyGoods
摘要:给你一部分钱和一些不同价钱的商品,如何在最多买K件商品的情况下尽可能多的花掉手里的钱。举例:口袋里的钱数: 10; K=2 产品价格: [3, 6, 8, 7, 9] 输出 3, 7Backtracking: 1 package BuyGoods; 2 import java.uti...
阅读全文
G面经prepare: X-Straight
摘要:Define “X-Straight” as X cards with consecutive numbers (X >= 3). Determine if the deck can be fully divided into sets of “X-Straight”.Example: 1, 2, ...
阅读全文
G面经prepare: Friends Recommendation
摘要:想想如果你用linkedin或者facebook, 给你一个人和他的朋友关系网,你会怎么给一个人推荐朋友一个例子就是A-B, A-C, B - D, B - E, C - D,这个时候问我应该推荐谁给A,我说D,因为他是BC的共同好友,而E只是B的好友,到这我才明白干啥,就是给一个图和里面的一个节点...
阅读全文
G面经prepare: set difference
摘要:给你A{1,2,3,4,4,5}, B{2,4},求A-B={1,3,4,5},很简单. visit 1只用一个HashMap 1 package TwoSets; 2 import java.util.*; 3 4 public class Solution { 5 public Arr...
阅读全文
G面经prepare: Straight Partition of A Deck of Cards
摘要:Define “Straight” as 5 cards with consecutive numbers. Determine if the deck can be fully divided into sets of “Straight”.Example: 1, 2, 3, 4, 4, 5, 5...
阅读全文
Summary: Merge Sort of Array && 求逆序对
摘要:常用算法(后面有inplace版本): 1 package ArrayMergeSort; 2 3 import java.util.Arrays; 4 5 public class Solution { 6 public int[] mergeSort(int[] arr) { 7 if (arr
阅读全文
Summary: Process & Tread
摘要:refer tohttp://www.programmerinterview.com/index.php/operating-systems/thread-vs-process/A process is an executing instance of an application. What do...
阅读全文
G面经Prepare: Search word delete sequence in dictionary
摘要:给一个单词一个字典,每次删除单词里任一个字母直到剩下一个字母,形成一个序列,比如office->offce->ofce->ofc->oc->c。问是否字典里存在一个这种序列 1 package checkDictExistSequence; 2 import java.util.*; 3 4 pu...
阅读全文
F面经prepare:strstr变种
摘要:* Given an integer k>=1 and two strings A and B (length ~n each); * Figure out if there is any common substring of length at least k. * (i.e. any str...
阅读全文
FB面经prepare: task schedule II
摘要:followup是tasks是无序的.一开始是有序的,比如说1, 1, 2, 1,一定要先执行第一个task1,然后等task1恢复,再执行第2个task1,再执行task2..... followup是无序的,就是不用按给的顺序执行,也就是可以先执行task1,然后task1还没恢复时,先执行ta...
阅读全文
FB面经prepare: Task Schedule
摘要:每种task都有冷却时间,比如task1执行后,要经过interval时间后才能再次执行,求总共所需时间。用HashMap保存每一个task的下一次可以开始执行的最早时间 1 package TaskSchedule; 2 import java.util.*; 3 4 public class ...
阅读全文
Lintcode: Minimum Subarray
摘要:Given an array of integers, find the subarray with smallest sum.Return the sum of the subarray.Have you met this question in a real interview? YesExam...
阅读全文
Leetcode: Power of Three
摘要:Given an integer, write a function to determine if it is a power of three. Follow up: Could you do it without using any loop / recursion? Recursion: 1
阅读全文
Lintcode: Permutation Index II
摘要:Given a permutation which may contain repeated numbers, find its index in all the permutations of these numbers, which are ordered in lexicographical ...
阅读全文
Lintcode: Permutation Index
摘要:Given a permutation which contains no repeated number, find its index in all the permutations of these numbers, which are ordered in lexicographical o...
阅读全文
Lintcode: Wood Cut
摘要:Given n pieces of wood with length L[i] (integer array). Cut them into small pieces to guarantee you could have equal or more than k pieces with the s...
阅读全文
Lintcode: Update Bits
摘要:Given two 32-bit numbers, N and M, and two bit positions, i and j. Write a method to set all bits between i and j in N equal to M (e g , M becomes a s...
阅读全文
Lintcode: Route Between Two Nodes in Graph
摘要:Given a directed graph, design an algorithm to find out whether there is a route between two nodes.Have you met this question in a real interview? Yes...
阅读全文
Lintcode: Flip Bits
摘要:Determine the number of bits required to flip if you want to convert integer n to integer m.Have you met this question in a real interview? YesExample...
阅读全文
Leetcode: Maximum Size Subarray Sum Equals k
摘要:Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If there isn't one, return 0 instead.Example 1:Given n...
阅读全文
Lintcode: Subarray Sum Closest
摘要:Given an integer array, find a subarray with sum closest to zero. Return the indexes of the first number and last number.Have you met this question in...
阅读全文
Lintcode: Remove Node in Binary Search Tree
摘要:iven 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...
阅读全文
Lintcode: Majority Number III
摘要: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.Have you met t...
阅读全文
Leetcode: Range Sum Query - Mutable && Summary: Segment Tree
摘要:Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.The update(i, val) function modifies nums by upda...
阅读全文
Leetcode: Create Maximum Number
摘要:Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum number of length k 0 && n-i-1>=count-j && res[j-1]arr2...
阅读全文
Leetcode: Maximum Product of Word Lengths
摘要:Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assum...
阅读全文
Leetcode: Shortest Distance from All Buildings
摘要:Adopted approach: start from each building, try to reach all 0. Alternertive approch can be start from each 0, try to reach all buildings. Which is wa
阅读全文
Leetcode: Remove Duplicate Letters
摘要:Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your...
阅读全文
Leetcode: Count of Smaller Numbers After Self
摘要:You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smal
阅读全文
Leetcode: Binary Tree Vertical Order Traversal
摘要:Given a binary tree, return the vertical order traversal of its nodes' values. (ie, from top to bottom, column by column).If two nodes are in the same...
阅读全文
Leetcode: Bulb Switcher
摘要:There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every ...
阅读全文
Leetcode: Super Ugly Number
摘要:Write a program to find the nth super ugly number.Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes o...
阅读全文
Leetcode: Burst Balloons
摘要: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...
阅读全文
Leetcode: Minimum Height Trees
摘要:Hint: build graph first, also buil indegree array, then find leaf and remove them among their neighbors, level by level. Until left less 2 nodes 这道题跟一
阅读全文
Leetcode: Generalized Abbreviation
摘要:Write a function to generate the generalized abbreviations of a word.Example:Given word = "word", return the following list (order does not matter):["...
阅读全文