随笔分类 - 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
阅读全文
摘要:By given an array [1,2,3]: Return all possible combinations. for example: [[], [1], [2], [3], [1, 2].... [1,2,3]]
阅读全文
摘要:We don't need to
阅读全文
摘要: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
阅读全文
摘要: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 |
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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:
阅读全文
摘要: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,
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要:Implement a job scheduler which takes in a function f and an integer n, and calls f after nmilliseconds
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要:/**@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(...
阅读全文