随笔分类 -  Algorithms

摘要:Give you set of meetings start time and end time, count how many meeting rooms needed. For example: We can use a memo table to store the at which time 阅读全文
posted @ 2019-03-27 02:03 Zhentiw 阅读(194) 评论(0) 推荐(0)
摘要:By given an array [1,2,3]: Return all possible combinations. for example: [[], [1], [2], [3], [1, 2].... [1,2,3]] 阅读全文
posted @ 2019-03-26 20:18 Zhentiw 阅读(329) 评论(0) 推荐(0)
摘要:We don't need to 阅读全文
posted @ 2019-03-26 00:35 Zhentiw 阅读(139) 评论(0) 推荐(0)
摘要:Given a sorted array, for example: Then we rotated it 1 time, it becomes: 2 times: So now given you an array which is rotated N times based on an sort 阅读全文
posted @ 2019-03-25 05:12 Zhentiw 阅读(207) 评论(0) 推荐(0)
摘要:It helps to understands how recursive calls works. So for our 'helper' function, when calling it, it stop there until when reach the end. one | two | 阅读全文
posted @ 2019-03-21 23:57 Zhentiw 阅读(151) 评论(0) 推荐(0)
摘要:Let's say we are going to find out number of occurrences of a number in a sorted array using binary search in O(log n) time. For example the given arr 阅读全文
posted @ 2019-03-20 20:36 Zhentiw 阅读(178) 评论(0) 推荐(0)
摘要:Given a stream of elements too large to store in memory, pick a random element from the stream with uniform probability. To solve the problem which n 阅读全文
posted @ 2019-03-20 03:22 Zhentiw 阅读(427) 评论(0) 推荐(0)
摘要:You run an e-commerce website and want to record the last N order ids in a log. Implement a data structure to accomplish this, with the following API: 阅读全文
posted @ 2019-03-20 02:24 Zhentiw 阅读(268) 评论(0) 推荐(0)
摘要:Given a list of integers, write a function that returns the largest sum of non-adjacent numbers. Numbers can be 0 or negative. For example, [2, 4, 6, 阅读全文
posted @ 2019-03-18 19:32 Zhentiw 阅读(381) 评论(0) 推荐(0)
摘要:Implement an autocomplete system. That is, given a query string s and a set of all possible query strings, return all strings in the set that have s a 阅读全文
posted @ 2019-03-17 18:10 Zhentiw 阅读(382) 评论(0) 推荐(0)
摘要:For example we have an array of words: What is the best data structure to store the data and easy for search? We can use Trie data structure, it is a 阅读全文
posted @ 2019-03-17 04:29 Zhentiw 阅读(246) 评论(0) 推荐(0)
摘要:For example we have array of meeting objects: For a day, 8 hours, we want to take as any meetings as possible: You should write function 'optimizeMeet 阅读全文
posted @ 2019-03-15 21:35 Zhentiw 阅读(1384) 评论(0) 推荐(0)
摘要:For example we have the array like this: First step is using Counting sort for last digit, in our example is: Then sort according to the last digit: T 阅读全文
posted @ 2019-03-14 15:45 Zhentiw 阅读(312) 评论(0) 推荐(0)
摘要:A unival tree (which stands for "universal value") is a tree where all nodes under it have the same value. Given the root to a binary tree, count the 阅读全文
posted @ 2019-03-13 20:54 Zhentiw 阅读(452) 评论(0) 推荐(0)
摘要:Implement a job scheduler which takes in a function f and an integer n, and calls f after nmilliseconds 阅读全文
posted @ 2019-03-13 06:05 Zhentiw 阅读(245) 评论(0) 推荐(0)
摘要:By given a tree structure, task is to find lowest common ancestor: For example, LCA(4, 5) --> >3 LCA(4,2) --> 1 LCA(3, 5) --> 3 LCA(6, 6) --> 6 Soluti 阅读全文
posted @ 2019-03-12 21:07 Zhentiw 阅读(207) 评论(0) 推荐(0)
摘要:By given an array of number, each number indicate the number of step you can move to next index: For example index = 0, value is 4, means at most you 阅读全文
posted @ 2019-03-11 22:07 Zhentiw 阅读(453) 评论(0) 推荐(0)
摘要:By given a binary tree, and a root node, find the deepest node of this tree. We have way to create node: Way to create tree: Way to construct tree: Th 阅读全文
posted @ 2019-03-11 21:00 Zhentiw 阅读(401) 评论(0) 推荐(0)
摘要:Let's say given a number of array, you should print out, all the subet of this array. Example: [1, 2] Output: > "" > 1> 2 > 1,2 The number of subset s 阅读全文
posted @ 2019-03-10 22:43 Zhentiw 阅读(142) 评论(0) 推荐(0)
摘要:/**@abstract * Write your own Math.pow(a int, b int) function * */ function pow (a, b) { let result = 0; let nigate = b = 2) { result = isEven ? pow(a, b / 2) * pow(a, b / 2) : a * pow(... 阅读全文
posted @ 2019-03-08 19:06 Zhentiw 阅读(192) 评论(0) 推荐(0)