1. Description Recursive way is based on computer program, the function calling stack. While iterative way is programmer use stack to simulate it. 2. Solution

Read More1. Description Design and Implement a data structure for LRU cache. It should support get and put. get(key) – Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.put(key, value) – Set or insert the value if the key is not already present. When the cache reached […]

Read More1. Description Given an integer, return its base 7 string representation. 2. Example 3. Solution 4. Complexity Time: O(n) Space: O(1)

Read More1. Description Asked by Google. Given a list of numbers and a number k, return whether any two numbers from the list add up to k. 2. Example Given [10, 15, 3, 7] and k of 17, return true, since 10+7 is 17. 3. Solution – 3 ways to solve it.

Read More1. Description Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too. You need to find the shortest such subarray and output its length. Example 1: Input: [2, 6, 4, 8, 10, 9, 15] Output: 5 Explanation: […]

Read More1. Description Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit. Note that you cannot sell a stock […]

Read More1. Description Give a pattern and a string, and check if the string follows the pattern. 2. Example 3. Solution 3.1 Wrong solution First, I was thinking, if I can use the AscII code to represent the pattern. For example: hello -> ‘a’, and hello -> ‘a’, world -> ‘b’, world->’b’. Use the data structure […]

Read More1. Questions What’s the best/worst running time of Merge Sort? O(nlogn), O(nlogn) What’s the best/worst running time of Quick Sort? O(n), O(n^2) What’s the worst running time for a look up in a HashTable? O(n) two reasons: if too many elements were hashed into the same key: looking inside this key may take O(n) time; […]

Read MoreGraph data structure is import. One main application is social media, like twitter and facebook. Twitter uses undirected graph, while facebook using Directed graph.

Read More