摘要:
题目是遇到偶数/2,遇到奇数 *3 + 1的题目,然后找一个range内所有数字的max cycle length。对于一个数字,比如说44,按照题目的公式不停计算,过程是 44, 22, 11, 8, 9 ,1(瞎起的),从44到1的这个sequence的长度,叫做cycle length。然后题
阅读全文
posted @ 2016-02-04 05:21
neverlandly
阅读(601)
推荐(0)
摘要:
首先是如何sort一个只有0和1的数组,要求inplace. follow up是告诉一个range,如何在O(N)时间内sort好 两个pointer可解 1 package Sorting; 2 import java.util.*; 3 4 public class InplaceSortin
阅读全文
posted @ 2016-02-04 01:27
neverlandly
阅读(374)
推荐(0)
摘要:
Given an expression string array, return the final result of this expression Have you met this question in a real interview? Yes Example For the expre
阅读全文
posted @ 2016-02-02 13:16
neverlandly
阅读(1202)
推荐(0)
摘要:
Give you an integer array (index from 0 to n-1, where n is the size of this array, value from 0 to 10000) and an query list. For each query, give you
阅读全文
posted @ 2016-02-02 07:22
neverlandly
阅读(679)
推荐(0)
摘要:
Given an integer array in the construct method, implement two methods query(start, end) and modify(index, value): For query(start, end), return the su
阅读全文
posted @ 2016-02-02 05:24
neverlandly
阅读(487)
推荐(0)
摘要:
Given an integer array (index from 0 to n-1, where n is the size of this array), and an query list. Each query has two integers [start, end]. For each
阅读全文
posted @ 2016-02-02 04:46
neverlandly
阅读(1003)
推荐(0)
摘要:
Given an integer array (index from 0 to n-1, where n is the size of this array), and an query list. Each query has two integers [start, end]. For each
阅读全文
posted @ 2016-02-01 12:30
neverlandly
阅读(701)
推荐(0)
摘要:
For an array, we can build a SegmentTree for it, each node stores an extra attribute count to denote the number of elements in the the array which val
阅读全文
posted @ 2016-02-01 11:46
neverlandly
阅读(599)
推荐(0)
摘要:
For a Maximum Segment Tree, which each node has an extra value max to store the maximum value in this node's interval. Implement a modify function wit
阅读全文
posted @ 2016-02-01 08:05
neverlandly
阅读(313)
推荐(0)
摘要:
For an integer array (index from 0 to n-1, where n is the size of this array), in the corresponding SegmentTree, each node stores an extra attribute m
阅读全文
posted @ 2016-02-01 07:52
neverlandly
阅读(814)
推荐(0)
摘要:
One way to serialize a binary tree is to use pre-oder traversal. When we encounter a non-null node, we record the node's value. If it is a null node,
阅读全文
posted @ 2016-02-01 07:31
neverlandly
阅读(1174)
推荐(0)
摘要:
The structure of Segment Tree is a binary tree which each node has two attributes start and end denote an segment / interval. start and end are both i
阅读全文
posted @ 2016-02-01 06:41
neverlandly
阅读(304)
推荐(0)
摘要:
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in ZigZag-order. Have you met this question in a real intervie
阅读全文
posted @ 2016-02-01 05:24
neverlandly
阅读(656)
推荐(0)
摘要:
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
阅读全文
posted @ 2016-01-28 02:07
neverlandly
阅读(713)
推荐(0)
摘要:
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:
阅读全文
posted @ 2016-01-25 10:42
neverlandly
阅读(1531)
推荐(0)
摘要:
求string str1中含有string str2 order的 subsequence 的最小长度DP做法:dp[i][j]定义为pattern对应到i位置,string对应到j位置时,shortest substring的长度,Int_Max表示不存在 1 package ShortestSu...
阅读全文
posted @ 2016-01-20 23:38
neverlandly
阅读(356)
推荐(0)
摘要:
求两个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...
阅读全文
posted @ 2016-01-20 11:52
neverlandly
阅读(311)
推荐(0)
摘要:
设定一个pattern 把 'internationalization' 变成 'i18n', 比如word是house,pattern可以是h3e, 3se, 5, 1o1s1等,给pattern和word,判断是否match, 1 package DataStreamAverage; 2 3 ...
阅读全文
posted @ 2016-01-20 07:06
neverlandly
阅读(348)
推荐(0)
摘要:
给一个datastream和一个fixed window size, 让我design一个class可以完成add number还有find average in the window. 就是不能用vector得用array. 当然用queue是最好的package DataStreamAverag...
阅读全文
posted @ 2016-01-20 01:12
neverlandly
阅读(369)
推荐(0)
摘要:
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...
阅读全文
posted @ 2016-01-19 13:01
neverlandly
阅读(246)
推荐(0)
摘要:
Backtracking: 我的code不光可以知道数目,还可以打印所有Pattern
阅读全文
posted @ 2016-01-19 12:02
neverlandly
阅读(689)
推荐(0)
摘要:
第二题 算法 给你一个arr 返回 T 或者 Farr的每个数代表从这个点开始跳几部,返回T的情况:从这个arr中任意一个数开始跳,可以在每个元素都跳到且只跳到一次的情况下返回到开始跳的元素比如[1,1,1,1,1,1] => T[0,1,1,1,1,1]=> F[7, 5, 2, 3] => F[...
阅读全文
posted @ 2016-01-19 04:12
neverlandly
阅读(430)
推荐(0)
摘要:
字符串重新排列,让里面不能有相同字母在一起。比如aaabbb非法的,要让它变成ababab。给一种即可Greedy:跟FB面经Prepare task Schedule II很像,记录每个char出现次数,然后用最大堆,把剩下char里面出现次数多的优先Poll出来组建新的string如果poll出...
阅读全文
posted @ 2016-01-19 02:35
neverlandly
阅读(364)
推荐(0)
摘要:
Given a sorting order string, sort the input string based on the given sorting order string. Ex sorting order string -> dfbcae Input string -> abcdeea...
阅读全文
posted @ 2016-01-18 12:41
neverlandly
阅读(341)
推荐(0)
摘要:
1 求问下各位大神,怎么判断一个按照Preorder traversal serialized的binary tree的序列是否正确呢?不能deserialize成树比如2 A) 9 3 4 # # 1 # # 2 # 6 # #是对的,因为表示3 94 / ...
阅读全文
posted @ 2016-01-18 10:35
neverlandly
阅读(431)
推荐(0)
摘要:
参考: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
阅读全文
posted @ 2016-01-18 05:44
neverlandly
阅读(1506)
推荐(0)
摘要:
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...
阅读全文
posted @ 2016-01-18 03:59
neverlandly
阅读(1749)
推荐(0)
摘要:
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
阅读全文
posted @ 2016-01-18 03:49
neverlandly
阅读(4071)
推荐(0)
摘要:
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...
阅读全文
posted @ 2016-01-17 12:23
neverlandly
阅读(297)
推荐(0)
摘要:
给定一个字符串,找出最多有多少个chunked palindrome,正常的palindrome是abccba, chunked palindrome的定义是:比如volvo, 可以把vo划分在一起,(vo) (l) (vo),那么它是个palindrome。求实现返回最大的chunk 数量。比如...
阅读全文
posted @ 2016-01-17 11:18
neverlandly
阅读(909)
推荐(0)
摘要:
给你一部分钱和一些不同价钱的商品,如何在最多买K件商品的情况下尽可能多的花掉手里的钱。举例:口袋里的钱数: 10; K=2 产品价格: [3, 6, 8, 7, 9] 输出 3, 7Backtracking: 1 package BuyGoods; 2 import java.uti...
阅读全文
posted @ 2016-01-17 06:01
neverlandly
阅读(505)
推荐(0)
摘要:
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, ...
阅读全文
posted @ 2016-01-16 04:35
neverlandly
阅读(708)
推荐(0)
摘要:
想想如果你用linkedin或者facebook, 给你一个人和他的朋友关系网,你会怎么给一个人推荐朋友一个例子就是A-B, A-C, B - D, B - E, C - D,这个时候问我应该推荐谁给A,我说D,因为他是BC的共同好友,而E只是B的好友,到这我才明白干啥,就是给一个图和里面的一个节点...
阅读全文
posted @ 2016-01-16 00:52
neverlandly
阅读(980)
推荐(0)
摘要:
给你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...
阅读全文
posted @ 2016-01-15 11:18
neverlandly
阅读(285)
推荐(0)
摘要:
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...
阅读全文
posted @ 2016-01-15 08:05
neverlandly
阅读(842)
推荐(0)
摘要:
常用算法(后面有inplace版本): 1 package ArrayMergeSort; 2 3 import java.util.Arrays; 4 5 public class Solution { 6 public int[] mergeSort(int[] arr) { 7 if (arr
阅读全文
posted @ 2016-01-14 12:34
neverlandly
阅读(378)
推荐(0)
摘要:
refer tohttp://www.programmerinterview.com/index.php/operating-systems/thread-vs-process/A process is an executing instance of an application. What do...
阅读全文
posted @ 2016-01-14 02:51
neverlandly
阅读(266)
推荐(0)
摘要:
给一个单词一个字典,每次删除单词里任一个字母直到剩下一个字母,形成一个序列,比如office->offce->ofce->ofc->oc->c。问是否字典里存在一个这种序列 1 package checkDictExistSequence; 2 import java.util.*; 3 4 pu...
阅读全文
posted @ 2016-01-13 09:56
neverlandly
阅读(294)
推荐(0)
摘要:
* 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...
阅读全文
posted @ 2016-01-12 10:27
neverlandly
阅读(539)
推荐(0)
摘要:
followup是tasks是无序的.一开始是有序的,比如说1, 1, 2, 1,一定要先执行第一个task1,然后等task1恢复,再执行第2个task1,再执行task2..... followup是无序的,就是不用按给的顺序执行,也就是可以先执行task1,然后task1还没恢复时,先执行ta...
阅读全文
posted @ 2016-01-11 07:12
neverlandly
阅读(1739)
推荐(0)