02 2017 档案
Pocket Gems面经prepare: Diamond and Ruby
摘要:类似Ones and Zeroes Dp[i][j][k] = Max(dp[i-5][j][k] + 5*10, dp[i][j-5][k] + 5*5, dp[i][j][k-1] + 1*25) reduce了dimension,其实还有一个维度是前k个格子,直接用倒序省掉了这个维度
阅读全文
FB面经Prepare: Find Longest Path in a Multi-Tree
摘要:解法就是在子树里面找最大的两个(或一个,如果只有一个子树的话)高度加起来。 对于每一个treenode, 维护它的最高的高度和第二高的高度,经过该点的最大路径就是: 最高高度+第二高高度,然后return 最高高度
阅读全文
FB面经Prepare: Friends Recommendation
摘要:有个getFriend() API, 让你推荐你的朋友的朋友做你的朋友,当然这个新朋友不能是你原来的老朋友 1 package fb; 2 3 import java.util.*; 4 5 public class ReferFriends { 6 public List recommendation(String name) { 7 List...
阅读全文
FB面经Prepare: Dot Product
摘要:1. two pointers 2. hashmap 3. 如果没有额外空间,如果一个很大,一个很小,适合scan小的,并且在大的里面做binary search
阅读全文
FB面经prepare: Count the number of Vector
摘要:分析: 如果是binary search找每个char的上下界,worst case要找n次,时间复杂度O(nlogn) 所以考虑每次比较start point和start point + 2^n位置上的数,假如一样就continue,不一样就在区间里面binary search找上界,这样wors
阅读全文
Leetcode: The Maze III(Unsolved Lock Problem)
摘要:Each time, first add the direction to the path, and then go with that direction, checking for hole along the way. When hit a wall, try to turn, and go
阅读全文
Leetcode: The Maze II
摘要:Solution of The Maze: https://discuss.leetcode.com/topic/77471/easy-understanding-java-bfs-solutionSolution of The Maze III: https://discuss.leetcode.
阅读全文
Leetcode: The Maze(Unsolved locked problem)
摘要:Search in the four possible directions when coming to a stopping point (i.e. a new starting point). Keep track of places that you already started at i
阅读全文
Leetcode: Max Consecutive Ones II(unsolved locked problem)
摘要:未研究: The idea is to keep a window [l, h] that contains at most k zero The following solution does not handle follow-up, because nums[l] will need to a
阅读全文
Leetcode: Find Permutation(Unsolve lock problem)
摘要:还没研究: For example, given IDIIDD we start with sorted sequence 1234567Then for each k continuous D starting at index i we need to reverse [i, i+k] port
阅读全文
G面经: Design Stock Price Display System
摘要:简单说来PriceUpdate就是添加新的(timestamp, price), Correction是改之前的(timestamp, price), 求实现当前high(), low(), last() LZ是用的Heap + HashMap, 特别问了时间复杂度(我猜到他想考heap的remov
阅读全文
U面经Prepare: Print Binary Tree With No Two Nodes Share The Same Column
摘要:这道题若能发现inorder traversal each node的顺序其实就是column number递增的顺序,那么就成功了一大半 维护一个global variable,colNum, 做inorder traversal 然后level order 一层一层打印出来
阅读全文
U面经Prepare: Web Address
摘要:虽然我觉得这道题用set倒着来就可以解决,但是看到一个Trie的做法也很不错 这里TrieNode.val不再是char, 而是String. children array也变成了Map<String, TrieNode> 我的做法:
阅读全文
FG面经Prepare: BST to Double LinkedList
摘要:Follow up: 第一步完成基础上,把这个new value插入BST中,一边插入一边记录沿途的大于value的root node(即走了该root node的left child),作为inorder successor. 找到inorder successor之后,通过其prev指针找到in
阅读全文
G面经Prepare: Longest All One Substring
摘要:这是一个简单版本of LC 424 Longest Repeating Character Replacement 又是Window, 又是Two Pointers Window还是采用每次都try to update left使得window valid, 每次都检查最大window
阅读全文
G面经Prepare: Print Zigzag Matrix
摘要:For instance, give row = 4, col = 5, print matrix in zigzag order like: [1, 8, 9, 16, 17] [2, 7, 10, 15, 18] [3, 6, 11, 14, 19] [4, 5, 12, 13, 20] 1 package GooglePhone; 2 3 import java.util...
阅读全文