My Notes

来源:互联网 发布:微信收费群设置 知乎 编辑:程序博客网 时间:2024/05/01 12:53
  1. Median of two sorted arrays (two slightly different ways)
    1. http://n00tc0d3r.blogspot.com/2013/04/median-of-two-sorted-arrays.html
  2. Given an integer array with positive numbers and a target, find out if there exists a contiguous sequence in the array whose sum equals to the given target.
    1. (59. facebook interview (actually google one and let us code))
  3. Largest rectangle in histogram, max amount of trapped rain water
    1. http://n00tc0d3r.blogspot.com/2013/06/trapping-rain-water.html
      1. Similar question but not entirely same
    2. Let us code this part as there seems to be simple straight intuitive answer for the tracking water problem
    3. Both questions can be easily extended to 3-dimension. Think about how to deal with them, not very difficulty actually.
    4. Similar but different question is about finding max amount of water that can be contained by just one pair of lines plus X-axis
      1. http://n00tc0d3r.blogspot.com/2013/02/container-with-most-water.html
        1. http://jane4532.blogspot.com/2013/05/container-with-most-water-leetcode.html
        2. Proof is simple and sound!
    5. Similar but different question is about finding max A[i] + A[j] + (j - i)
      1. You use math formula to make it simple
      2. Brute-force way also works as there could be just one "largest" value, considering both element and its index
      3. (58. interesting interview helped by math conversion)
  4. Easy extension is to calculate max volume for N x N matrix, max water trapped in by N x N matrix
    1. The basic idea is dimension reduction, 3 -> 2 -> 1
      1. (59. amazon interview (similar idea of reducing matrix dimension to calculate max rectangle with equal number of 0 and 1))
    2. Similar but different google interview question about finding out all cell that can be connected to 4 edges of N x N matrix
      1. (58. google interview (kind of hard and about n x n matrix with elevation))
      2. (58. google interview (another n x n matrix with elevation))
  5. When to use what sorting algorithm, why most of time quick sort is better than merge and heap sort
  6. Some good algorithms based upon trie
  7. In an integer array there is only one element that occurs just once and all other elements occur exactly times. How to find the particular element.
    1. Very good solution here
  8. Shortest string containing all 4-digit number (0000-9999, De Bruijn sequence)
    1. http://en.wikipedia.org/wiki/De_Bruijn_sequence
    2. (59. google interview (including facebook and good brain teaser and kind of old))
  9. DP to minimize cost of cutting logs
  10. Print out all numbers containing 5 for a given n (groupon)
  11. Construct a long string by repeating a short string (amazon) 
  12. Fib series in O(logn)
  13. Wild card matching and regexp matching
    1. http://swtch.com/~rsc/regexp/regexp1.html
  14. Scrambled strings (high dimensional DP)
    1. The thought is good - how to optimize recursion by using DP
    2. http://www.robbiehaoyan.com/category/dynamic-programming
    3. http://n00tc0d3r.blogspot.com/2013/05/scramble-string.html
    4. http://blog.theliuy.com/scramble-string
    5. https://haixiaoyang.wordpress.com/2012/04/30/scramble-string-problem
  15. Permutation and combination
    1. how to deal with duplicate element
    2. next permutation
    3. how to find k-th permutation efficiently
      1. http://n00tc0d3r.blogspot.com/2013/05/permutation-sequence.html
      2. this idea is more like how to find out all number containing digit 4 (use math to simplify calculation)
  16. Huffman code
  17. Given two sorted array M and N with size m and n, each time pick one number from M and one number from N and add them them. Try to find the k smallest sum (given two ascending sorted array A and B)
  18. Dutch national flag problem
  19. Given an int array, find out if there exist 3 ints that can be used to contruct a triangle in O(nlogn). (51. google interview (3 numbers to form triangle))
  20. Given a set of movie starting / ending times, find out at most how many movies can be watched without conflict. Is that a graph problem? (51. google interview (reasonable but also requires some work)) 
  21. K-d tree to find out nearest neighbor in a given points set 
  22. Given n x n matrix with increasing rows and columns, find out k-th smallest element in O(nlogn)
  23. 平面N个点,找两点连线正好把点分到两半 
  24. Given a function of "int Read4096(char * buf)" implement "int ReadBytes(char * buf, num_bytes)"
  25. Sort linked list (better use merge sort rather than quick sort)
  26. Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. Very smart ideahere
    1. Very good algorithm explanation, http://stackoverflow.com/questions/21085160/in-a-matrix-put-0-in-the-row-and-column-of-a-cell-which-contains-0-without-using
  27. Mirror a BT
    1. Another good BT question about pointing to next node on the same level with O(1) space, http://n00tc0d3r.blogspot.com/2013/05/populating-next-right-pointers-for-each.html
  28. Gray code (54. facebook interview (gray code))
    1. Some good discussion about Gray code application, http://n00tc0d3r.blogspot.com/2013/03/gray-code-and-variants.html
  29. Given a set of records, each has starting time, ending time and weight, find out all records that have no overlap of time and have max weight (54. amazon interview (seems very tricky))
  30. How to calculate Fibonacci umber efficiently
    1. https://github.com/mitkook/Career-Cup-CPP-Solutions/blob/master/Chapter%208/Ex_8_1.h
    2. (54. fib number calculation)
  31. Count reverse ordered pair
    1. stackoverflow
    2. (53. facebook interview (how to use reverse ordered pair))
  32. In place convert abcd1234 to a1b2c3d4
    1. Iterative way (abcd1234 -> abc1d234 -> ab1c2d34 -> a1b2c3d4)
    2. Recursive way (54. google interview (good recursion))
  33. Given three arrays A,B,C containing unsorted numbers. Find three numbers a, b, c from each of array A, B, C such that |a-b|, |b-c| and |c-a| are minimum.
    1. Convert to math problem to ease coding
    2. (55. amazon intervie (good idea to convert to math problem before coding))
  34. Given a set of points in 2d grid space. Find a grid point such that sum of distance from all the points to this common point is minimum.
    1. Just X/Y axis median?
    2. (57. facebook interview (seems high frequent but how to prove))
  35. Reservoir sampling
    1. http://en.wikipedia.org/wiki/Reservoir_sampling (with proof)
    2. http://n00tc0d3r.blogspot.com/2013/08/reservoir-sampling-and-variants.html
  36. Find out the majority element from an array in linear time with constant extra space
    1. Moore's voting algorithm
  37. Matrix with numbers (either just 0/1 or any integer) and need to find out a certain shape (square, rectangle) with min/max sum
    1. Very smart idea using max rectangle from histogram on each row (for a matrix with 0/1 only), after summing numbers vertically
      1. http://n00tc0d3r.blogspot.com/2013/04/maximum-rectangle.html
    2. This is kind of different to another one that is to find out a rectangle with max sum for a given matrix with any integer, using max sum of continuous subarray
    3. Please check my saved notes about matrix
  38. Find the longest string containing valid ( and ). For example, (()() is 4, (((()))() is 8. Kind of tricky, http://n00tc0d3r.blogspot.com/2013/04/longest-valid-parentheses.html. I don't seem to understand the solution.
    1. Let us code this one and see if there is anything missing or incorrect
  39. Given an int array find out the length of max consecutive integers. For example, 100, 3,1,2,4,200 is 4
    1. Let us code and don't over-complicate problem
    2. http://n00tc0d3r.blogspot.com/2013/03/longest-consecutive-sequence.html, the thought is great too
  40. Interesting tree related questions
    1. Construct a BST from sorted linked list (not array!) faster, http://n00tc0d3r.blogspot.com/2013/02/covert-sorted-arraylist-to-bst.html. More a bottom-up approach
    2. Pay attention to path that can start / end on any node: http://n00tc0d3r.blogspot.com/2013/01/tree-path-sum.html
  41. Best time to buy/sell stocks with at most 2 times transactions
    1. http://n00tc0d3r.blogspot.com/2013/01/best-time-to-buy-and-sell-stock.html
    2. Let us code and try to understand it
  42. 3/4SUM problem
    1. http://n00tc0d3r.blogspot.com/2013/01/2sum-3sum-4sum-and-variances.html
      1. The idea of using two pointers from both ends are nice, since you are left with only one choice to pick up the pointer and move, and you get linear time in the worst case. If you instead use two pointers from same end, then you don't know which pointer to move first which second.
  43. Intervals with starting/ending time plus cost overlapping questions:
    1. Max number of overlapping
    2. Minimal conference rooms needed
    3. Max cost without overlapping
    4. (58. facebook interview (intervals related))
    5. (59. facebook interview (hard and high frequent one))
      1. A relatively hard one combining DP as well, but the idea of sorting by end time then binary-inserting by start time is very good
  44. Online judge and compiler
    1. Leetcode
    2. Lintcode
      1. (59. facebook interview (using another online judge lint))
    3. topcoder
    4. codechef
    5. hackerrank
    6. codeeval
    7. collabedit
  45. Interesting local startups:
    1. http://www.intentsoft.com
    2. http://qumulo.com
    3. http://www.breakoutlist.com (interesting collection list from Y Combinator)
  46. Max prod in an given array with both fraction and negative numbers
    1. Not yet find the answer
    2. Below is answer for an easy case without fraction number: https://www.quora.com/How-do-I-solve-maximum-product-subarray-problems
      1. Not sure it's correct or not
      2. It might be correct for generic case including negative and fraction numbers
      3. Similar to Kadane's algorithm
  47. RESERVED
0 0
原创粉丝点击