Beruflich Dokumente
Kultur Dokumente
❌ Tree Traverse 5
❌ Max Heap, Min Heap using Priority Queue 5
❌ List data structure methods! 5
❌ Questions related to range, intervals!!! 5
系统设计: 6
https://soulmachine.gitbooks.io/system-design/content/cn/search-engine.html 6
http://systemdesigns.blogspot.com/2016/01/cassandra-vs-dynamo.html 6
[面试经验] LinkedIn Top10高频系统设计问题总结+讨论 6
高频top k 6
data stream, 内存有限,输出最大的K个数 6
top N exceptions in recent K time, 6
统计最近5min的request 6
Top k个shared links ++ 6
https://github.com/FreemanZhang/system-design/blob/master/linkedin/topk.md 6
top N issue. 巨大的数据怎么办 7
设计一个类似youtube的网站 7
设计linkedin Ads. 7
短链接 ++++++ 7
设计日历++ 7
设计亚麻购物界面 8
问已经有个sharing service 可以share 任何link。 ++ 8
设计一个日志系统 8
设计个service,处理push和pull请求。 9
delay scheduler. +++ 9
设计job推荐系统 9
设计news feed 9
KV store ++++ 9
如何判断friend ++ 9
如何sharding inverted index。 9
Design Monitoring System, 10
设计一个dashboard 10
地图 10
H2O 10
Blacklist IP 10
给你一个userID,返回能cover住这个user的全部advertisers。 10
设计一个单机的类 stream 的单写多读的系统 10
又是一个单机类 stream 单写多读系统 11
如何设计一个model判断一条信息是不是广告 11
设计一个可以查询数据的系统 11
Real time Content Delivery 11
多个server怎么解决global id unique的问题, 11
Union and Intersection of two sorted array 12
X 68. 12
Binary Search 16
✅❌ 272 Closest Binary Search Tree Value II +++++ 16
✅Sol 1. Convert BST to sorted array (in order traversal) 17
✅ Sol 2. During in-order traversal 18
❌ Sol 3. Two stacks. One storing larger than target, the other smaller than target. 18
❎69 Sqrt(x) +++++ 19
Variant: Input is float 20
❎34 Search for a Range +++ 20
❎❌367 Valid Perfect Square 20
❎Sol 1. Binary Search O(lgn) 20
❎Sol 2. Math arithmetic sequence O(sqrt n) 21
DP / Memorization 21
✅ 256 Paint House ++++ 21
✅ 265 Paint House II ++++ 21
✅Sol 1. Time O(NK), Space O(NK) 21
✅Sol 2. Time O(NK), Space O(1) 22
✅❌72 Edit Distance +++ 22
Variant: 23
❌464 Can I Win 23
✅❌ 361 Bomb Enemy 23
✅❌ 139 Word Break 24
DFS/BFS/Backtracking 25
✅ 200 Number of Islands ++++++++ 25
❌Variant 25
230 Kth Smallest Element in a BST +++++ 26
Sol 1: with help of additional vector 26
❌⭐ Sol 2: count k during in-order traversal 26
❌671 Second Minimum Node In a Binary Tree 27
❌ 366 Find Leaves of Binary Tree ++++++++ 27
❌ 339 Nested List Weight Sum 27
❌364 Nested List Weight Sum II ++ 28
606. Construct String from Binary Tree 28
❌46 Permutations I (no duplicates) ++ 28
❌47 Permutations II (with duplicates) ++ 29
❌254 Factor Combinations 29
❌113 Path Sum II 30
Tree, Graph 30
102 Binary Tree Level Order Traversal 30
✅❌ 103 Binary Tree Zigzag Level Order Traversal 30
Array 32
❌ 277 Find the Celebrity 33
Variant: 33
✅243 Shortest Word Distance 33
❌✅244 Shortest Word Distance II 34
53 Maximum Subarray 34
❌152 Maximum Product Subarray 34
❌235 Lowest Common Ancestor of a Binary Search Tree + 35
❌236. Lowest Common Ancestor of a Binary Tree + 35
Variant: has parent node! 35
Thread-safe Hashtable put get 实现 (multithreading) 36
N dimensional image volume 37
求两个linked list 是否 merge。+++ 37
❌282 Expression Add Operators 37
多维数组求和 37
516 Longest Palindromic Subsequence 37
322 Coin Change 37
698 Partition to K Equal Sum Subsets +++ 37
Variant 37
76 Minimum Window Substring +++ 37
❌ 721. Accounts Merge 38
341. Flatten Nested List Iterator +++ 38
flatten 4-direction doubly linked list 38
3 degree好友 39
设计一个支持produce h和o consume并生成h2o的class 39
找convex function的min 39
❌149 Max Points on a Line ++++ 39
39 Combination Sum ++ 40
297 Serialize and Deserialize Binary Tree +++ 40
205. Isomorphic Strings 40
349 Intersection of Two Arrays 40
606 Construct String from Binary Tree 40
实现 string replace 40
✅344 Reverse String 40
❌Variant 41
❌56 Merge Intervals ++ 41
57 Insert Interval 41
❌127 Word Ladder 41
Given number array and k, see if array could be divided to k buckets which all have same sum +++ 42
给一个array 和target,要找出所有subset, summary是target的。 42
给你一个int c, 返回boolean 表示是否可以有a^2 + b^2 = c^2 存在,a,b,c > 0 42
❌647 Palindromic Substrings 42
切匹萨,推导并总结出dp方程++ 42
Math 42
13. Roman to Integer ++++ 42
✅12. Integer to roman 42
✅ 238. Product of Array Except Self 43
187 Repeated DNA Sequences 43
Sol 1. Naive, a lot of storage 43
Sol 2. Compress! Last three bit of ACGT 43
地图 44
按权重返回随机数。 44
打印经过城市停车站的所有路线。 44
一个function实现计算器里的undo以及redo功能。 44
Someone’s Summary? 45
Bold Words in String 46
TODO List:
❌ Tree Traverse
2.
struct compare {
bool operator()(const int& l, c
onst i
nt& r) { return l > r; }
};
priority_queue<int,vector<int>, compare > pq;
https://soulmachine.gitbooks.io/system-design/content/cn/search-engine.html
http://systemdesigns.blogspot.com/2016/01/cassandra-vs-dynamo.html
高频top k
不过我觉得可以考虑分bucket,然后通过消息队列去消费log, 这个是架构上的,存储上,算法上考虑到数据的波动
应该不会太大,可以缓存一波数据,从而请求时不用任何人计算。然后定期更新缓存。存储上可以分析数据量的
大小,考虑分布式内存数据库或者存本机内存,存本机内存可以考虑如何sharding,然后有个master集中处理的
结果。总之就是无非几点,跨机器如何通讯(消息队列),算法(基本的数据结构,能不能缓存),存储(本机内存,
分布式内存数据库,关系型数据库,nosql数据库,还是文件系统),然后就是如何负载均衡(一致性哈希?需不需
master?等等)。
统计最近5min的request
https://github.com/FreemanZhang/system-design/blob/master/linkedin/topk.md
top N issue. 巨大的数据怎么办
设计一个类似youtube的网站
问了几个关于network latency, application I/O latency等等的小问题,然后设计一个类似youtube的网站
,画下基本架构
设计linkedin Ads.
每个user有一些attributes. 比如什么专业,什么level。每个广告有其针对的attribute。比如广告a针对
level 4以上的software engineer。设计系统当user登陆时根据他的attributes推送相应广告。基本就是一
个inverted index就搞定了,然后又聊了一些优化和follow up
短链接 ++++++
问题很多,需要处理single point failure 和scale
如果想统计过去 5mins, 1 hour request的tiny url要怎么保存 提取。
如何做load balance. 如何做主从备份。
自增id要加随机因子,不能被predict出来
设计日历++
基本上我就列了下面几个service 然后逐个说了一下如何实现的。
主要在讨论如何database里面的table
create event
check availability
add people event
event alert
https://www.jiuzhang.com/qa/5490/
这个问题比较大,在面试的时候我们可以先设计一个简单的Calendar,然后逐渐优化,正如这里所说
的不考虑重复事件,用户少。
1. 我们要看Calendar支持哪些功能
○ 列出年月日,当前这周,当前这个月根据当前的日期
○ 支持放一个event在calendar上,放入event上之后,你可以加入某人到这个event中,并
且给他发notification
○ 支持放一个周期性的event(如题目描述这个不需要考虑)
○ event来临前的提醒,比如前10分钟你需要发出提醒
○ 把events按照时间线列在calendar上
○ 以上是我们大概需要实现的功能,比如Google calendar功能非常丰富,实际上我们是不
需要在面试中一一列出来的,列出主要的即可
2. 开始设计table (也就是数据库的schema)
○ User profile 用户的基本信息table是需要的,存user id,user email(需要发邮件邀请加入event),
user nick
,什么时候结束),description(event的大致描述),status (表示是否提醒过)等等
么对于这个event有哪些人参数我们可以做一个query得到,同样的,一个人参与了哪些events,也可
以用一个query得到。当然你也可以把参与的人存入Events table当中,不需要这个关联。
3. storage 存储介质:
○ 我们可以选择SQL 也可以选择NOSQL来存(正如题目描述中的,user并不是很多)
4. 实现notify功能
○ 我们可以实现一个消息队列,把快要开始的而且status是没有提醒过的events丢进消息队列中,消息
队列的头部负责查看是否刚好是十分中,如果是的,那么就推一个notification给用户,提醒到event马
上就要开始了。
5. 实现邀请功能
○ 一旦你把一些人加入到这个event中,那么我们给用户一个提示,是否要发邮件给这些人,所以我们还
需要实现一个邮件发送的功能。
设计亚麻购物界面
设计一个日志系统
储存其他服务生成的日志,支持关键字搜索。一直问日志应该怎么传输.
传输感觉应该是用Kafka?支持关键字搜索这个应该就是扯一下MapReduce,Inverted Index吧?
设计个service,处理push和pull请求。
假设每个push请求都有个unique incremental ID和它的payload,每个pull请求都有个id作为它的参数;
对于pull请求,要返回所有push请求中ID最大的且不大于pull id的请求的payload(如果push 1, x, push
4, y, pull 5返回y)
设计job推荐系统
设计news feed
KV store ++++
https://soulmachine.gitbooks.io/system-design/content/cn/key-value-store.html
https://www.jiuzhang.com/qa/4818/
V可以很大,K可以进memory,memory中只能使用hashtable这种data structure;可以使用文件系统存KV pair
,但是文件系统只支持delete,create,append,seek,read
每一个put的带一个microsecond的time to live。ttl用circular buffer
key可以在memory,value太大需要disk,只讨论单机。file system只支持file creation deletion,random read,
file content append,不支持override, random delete。
文件系统是类似 HDFS 一样的
Value要存到disk上问得非常细节,例如 写内存与写磁盘的先后顺序,逐条 log 演示做 log compaction 的步骤
如何判断friend ++
friend of friend,friend of friend of friend,followup如何shard data提高效率
设计系统查询A和B 是否为1度好友,2度好友和3度好友
https://www.quora.com/How-does-LinkedIn-compute-mutual-friend-pathways-so-quickly
设计一个dashboard
dashboard是一个地图,当有新用户注册账号时,需要实时在dashboard上显示用户位置?
follow up:前端用什么library?(d3.js),需要向前端发送哪些数据?(经纬度或者geohash),push vs pull?怎
么实现push service?(消息队列)?怎么测试?
地图
上面有很多点, 每个点是个object, x, y 坐标都给了, 比如{x: 5, y: 5}
已知 包含所有点的 array, 某一个点,和半径d, 写一个function 返回到这个点的距离小于或等于d 的所有点。怎么
优化。我当时答得是把整个地图分成小的区域,每一小块2d的正方形。然后找这个点所在的方块和周围的几个方
块。这样就不用遍历地图里所有的点了。
H2O
水是2个h一个o组成. 好多的thread 要多call func_h() 或者 func_o() call的时候,产生一个原子(h或者o),如果前
面已经有thread提供过h 还有o,就继续,产生一个h2o 如果没有足够的h和o,wait()
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=295838
Blacklist IP
这个list会增加删减条目,每一个request都会来lookup这个list。
给你一个userID,返回能cover住这个user的全部advertisers。
这里假设用户注册的时候你知道他的location data(longtitude,lattitude)这个是固定的,每个advertiser也有
location data,除去longtigude,lattitude,还有一个radius,表示这个advertiser的覆盖范围。先讨论算法实现以及算
法优化,然后就是基本system design讨论,如何存储,如果提高性能等等。
如何设计一个model判断一条信息是不是广告
设计一个可以查询数据的系统
我就提出直接用LAMP。然后就问如果增加了Query的QPS怎么办,增加了input的数据量怎么办,我就提到了用
sharding啦,Load Balancer啦,Kafka啦之类的,然后分析trade off和计算了下需要的机器数量
Real time Content Delivery
多个server怎么解决global id unique的问题,
专门用一个server去分配id被否定,会有single point failure,后来加入server id做prefix,就好
https://soulmachine.gitbooks.io/system-design/content/cn/distributed-id-generator.html
Union and Intersection of two sorted array
http://blog.csdn.net/pplin/article/details/60574397
X 68.
Binary Search
✅❌ 272 Closest Binary Search Tree Value II +++++
http://www.cnblogs.com/grandyang/p/5247398.html
❌ Sol 3. Two stacks. One storing larger than target, the other smaller than target.
vector<int> closestKValues(TreeNode* root, double target, int k) {
vector<int> ret;
stack<TreeNode*> pre, suc;
while (root) {
if (root->val <= target) {
pre.push(root);
root = root->right;
}
else {
suc.push(root);
root = root->left;
}
}
while (k--) {
if (suc.empty() || !pre.empty() && target - pre.top()->val < suc.top()->val - target)
{
ret.push_back(pre.top()->val);
getPredessor(pre);
}
else {
ret.push_back(suc.top()->val);
getSucessor(suc);
}
}
return ret;
}
void getPredessor(stack<TreeNode*> &pre) {
TreeNode* t = pre.top();
pre.pop();
if (t->left) {
pre.push(t->left);
while (pre.top()->right) {
pre.push(pre.top()->right);
}
}
}
void getSucessor(stack<TreeNode*> &suc) {
TreeNode* t = suc.top();
suc.pop();
if (t->right) {
suc.push(t->right);
while (suc.top()->left) {
suc.push(suc.top()->left);
}
}
}
DP / Memorization
✅ 256 Paint House ++++
int minCost(vector<vector<int>>& costs) {
if (!costs.size()) {return 0;}
for (int i = 1; i < costs.size(); i++) {
costs[i][0] += min(costs[i - 1][1], costs[i - 1][2]);
costs[i][1] += min(costs[i - 1][0], costs[i - 1][2]);
costs[i][2] += min(costs[i - 1][1], costs[i - 1][0]);
}
return min(costs[costs.size() - 1][0], min(costs[costs.size() - 1][1], costs[costs.size()
- 1][2]));
}
✅ 265 Paint House II ++++
Variant:
❌❌edit distance to palindrome,给一个string,变成palindrome的edit distance是多少 (not in leetcode?)
Sol1. Recursive
bool dfs(vector<int> &nums, int idx, vector<int> &sums, int n, int &k, int &sum) {
//39, 37, 23, 23, 12, 6, 4, 3, 2, 1
if (n == idx) {return true;}
for (int i = 0; i < k; i++) {
if (sums[i] + nums[idx] > sum) {continue;}
sums[i] += nums[idx];
if (dfs(nums, idx + 1, sums, n, k, sum)) {return true;}
sums[i] -= nums[idx];
}
return false;
}
bool canPartitionKSubsets(vector<int>& nums, int k) {
int sum = 0;
for (int i : nums) {sum += i;}
if (sum % k != 0) {return false;}
sum /= k;
sort(nums.begin(), nums.end());
reverse(nums.begin(), nums.end());
vector<int> sums(k);//K buckets to store the values
return dfs(nums, 0, sums, nums.size(), k, sum);
}
切匹萨,推导并总结出dp方程++
dp[0] = 1, dp[n] = dp[n - 1] + n
x(n) =n (n + 1) / 2 + 1
DFS/BFS/Backtracking
✅ 200 Number of Islands ++++++++
int numIslands(vector<vector<char>>& grid) {
if (grid.size() == 0) return 0;
if (grid[0].size() == 0) return 0;
int res = 0;
for (int i = 0; i < grid.size(); i++) {
for (int j = 0; j < grid[0].size(); j++) {
if (grid[i][j] == '1') {
res += 1;
dfs(grid, i, j);
}
}
}
return res;
}
void dfs(vector<vector<char>>& grid, int x, int y) {
grid[x][y] = '0';
if (x > 0 && grid[x - 1][y] == '1')
dfs(grid, x - 1, y);
if (x < grid.size() - 1 && grid[x + 1][y] == '1')
dfs(grid, x + 1, y);
if (y > 0 && grid[x][y - 1] == '1')
dfs(grid, x, y - 1);
if (y < grid[0].size() - 1 && grid[x][y + 1] == '1')
dfs(grid, x, y + 1);
}
❌Variant
完了改成求山谷数量,意思就是说二维数组里的整数值代表高度,求有几个local的最小值。举个例子,比如有一
个3X3的矩阵是matrix = [[1,2,0],[3,1,0],[-1,0,2]], 那么matrix[2][0]这个-1是一个山谷,右上角的两个上下连着的0
也是一个山谷。超出矩阵范围的坐标认为是有无限大的数。所以最后返回3.
40 Combination Sum II
vector<vector<int> > combinationSum2(vector<int> &num, int target)
{
vector<vector<int>> res;
sort(num.begin(),num.end());
vector<int> local;
findCombination(res, 0,
target, local, num);
return res;
}
void findCombination(vector<vector<int>>& res, const int order, const int target, vector<int>&
local, const vector<int>& num)
{
if(target==0)
{
res.push_back(local);
return;
}
else
{
for(int i = order;i<num.size();i++) // iterative component
{
if(num[i]>target) return;
if(i>order && num[i]==num[i-1]) continue; // check duplicate combination
local.push_back(num[i]),
findCombination(res,i+1,target-num[i],local,num); // recursive componenet
local.pop_back();
}
}
}
Tree, Graph
98. Validate Binary Search Tree
bool isValidBST(TreeNode* root) { return isValidBST(root, NULL, NULL);}
bool isValidBST(TreeNode* root, TreeNode* min, TreeNode* max){
if (!root) return true;
if (min && root->val <= min->val) return false;
if (max && root->val >= max->val) return false;
return isValidBST(root->left, min, root) && isValidBST(root->right, root, max);
}
102 Binary Tree Level Order Traversal
Sol1. Iterative
TreeNode* upsideDownBinaryTree(TreeNode* root) {
TreeNode* parent = nullptr; //cur’s parent node
TreeNode* next = nullptr; //cur’s left node
TreeNode* right = nullptr; //cur’s sibling right
TreeNode* cur = root;
while (cur) {
next = cur->left;
cur->left = right;
right = cur->right;
cur->right = parent;
parent = cur;
cur = next;
}
return parent;
}
❌❌❌Sol2. Recursive
TreeNode* upsideDownBinaryTree(TreeNode* root) {
if (!root || !root->left) { return root;}
TreeNode* cur_left = root->left;
TreeNode* cur_right = root->right;
TreeNode* new_root = upsideDownBinaryTree(root->left);
cur_left->left = cur_right;
cur_left->right = root;
root->left = nullptr;
root->right = nullptr;
return new_root;
}
Variant:
类似于find celebrity. 叫做find influencer. input是一个2d boolean array, 每个index 代表一个人。比如
matrix[1][0] = true,表示1 follow 0,如果是matrix[1][0] = false,表示1没有follow 0. influencer的定义是所有除了他
以外的人都follow他,而他没有follow任何人。先说了一个暴力法O(n^2),他说能O(n)解吗,写了一个用queue的
方法,他又问能不用额外空间吗。然后经他提示,写了个不用额外空间的O(n)解法。
53 Maximum Subarray
int maxSubArray(vector<int>& nums) {
if (nums.size() == 0) { return 0;}
vector<int> cumsum(nums.size() + 1);
cumsum[0] = 0;
for (int i = 1; i <= nums.size(); i++) {
cumsum[i] = cumsum[i - 1] + nums[i - 1];
}
int cur_min = 0; //easy to make mistake here!!!
int cur_max = INT_MIN;
for (int i = 1; i < cumsum.size(); i++) { //start from 1! cur_max =
max(cur_max, cumsum[i] - cur_min);
cur_min = min(cur_min, cumsum[i]);
}
return cur_max;
}
Let’s look at finding first. If the content of a map/set is fixed, finding is thread-safe by nature. (for most implementations,
we do not discuss the rare cases)
How about inserting and removing? To make it concurrency, it must be able to perform more than one operations at the
same time by different threads. This easily come up with an idea of partition an array. By partitioning an array into different
section, each section can be accessed separately by different threads.
But when an inserting or removing is invoked, the inner map is locked only instead of lock the whole outer map.
As long as the content of outer map is fixed, it does not need to be locked/unlocked.
If the number of hash slots is big enough, in normal cases, the chance of accessing a same inner map by more than one
threads can be reduced significantly.
Look at the GitHub repository here for a sample implementation based on the ideas above:
https://github.com/huxia1124/ParallelContainers
看 ParallelContainers/STXUtility.h
多维数组求和
Variant
follow up是找出这些份 返回一个List<List<Integer>>
Search range??
思路是这样:
1. 给定任意一个node,往left走到head,往右一直走到tail(这个操作要重复很多遍所以可以定义getHead
getTail两个function);.
2. 从head开始走,判断有没有up node,有的话,从up node一直往左走到新的head,一直往右走到新的tail,把
这个head链接到原来的tail,把旧的tail的值赋成新值
3. 把up node和刚才那个node之间的up & down link断掉,有小trick,不细讲了;
4. 判断有没有down node,有的话,重复上面两步操作;
5. 操作结束或者本来就没有up down node的话就往下,一直走到那个被更新过很多遍的tail...
当然不一定全都挪到tail,也可以挪到node.next,但个人觉得挪到tail比较好visualize。
❌followup如果有环怎么办。要求都是constant space???
这个是O(1) space, 基本上是O(N) time, 虽然getHead和getTail两个function可能跑很多遍,最终应该也还是O(N)
吧?不过最后还讨论到这一步。
public class MultiListToDoubleList {
static class MultiListNode {
int val;
MultiListNode pre;
MultiListNode next;.
MultiListNode up;.
MultiListNode down;.
}
public static void convert(MultiListNode head) {
if (head == null) { return;}
MultiListNode tail = head;
while (tail.next != null) {tail = tail.next;}
MultiListNode cur = head;
while (cur != null) {
if (cur.up != null) {
MultiListNode up_head = cur.up;
while (up_head.pre != null) {up_head = up_head.prev;}
tail.next = up_head;
up_head.pre = tail;
while (tail.next != null) {tail = tail.next;} //update tail!!!
cur.up.down = null;
cur.up = null;
}
if (cur.down != null) {
MultiListNode dn_head = cur.down;
while (dn_head.pre != null) {dn_head = dn_head.prev;}
tail.next = dn_head;
dn_head.pre = tail;
while (tail.next != null) {tail = tail.next;}
cur.down.up = null;
cur.down = null;
}
cur = cur.next;.
}
}.
}
3 degree好友
找convex function的min
实现 string replace
❌Variant
Should be within a sentence. Do not change the position of each word, but reverse them!
57 Insert Interval
vector<Interval> insert(vector<Interval>& intervals, Interval newInterval) {
vector<Interval> ret;
int idx = 0;//1. Deal with intervels before new
while (idx < intervals.size() && newInterval.start > intervals[idx].end) {
ret.push_back(intervals[idx]);
idx++;
} //2. Merge with intervls overlapping with new
while (idx < intervals.size() && newInterval.end >= intervals[idx].start) {
newInterval.start = min(newInterval.start, intervals[idx].start);
newInterval.end = max(newInterval.end, intervals[idx].end);
idx++;
} //3. Deal with intervals after
ret.push_back(newInterval);
while (idx < intervals.size()) {
ret.push_back(intervals[idx]);
idx++;
}
return ret;
}
Math
13. Roman to Integer ++++
int romanToInt(string s) {
int len = s.length();
if (len == 0) {return 0;}
unordered_map <char, int> T ={
{'I', 1},
{'V', 5},
{'X', 10},
{'L', 50},
{'C', 100},
{'D', 500},
{'M', 1000},
};
int ret = T[s[len - 1]];
for (int i = len - 2; i >=0; i--) {
if (T[s[i]] >= T[s[i + 1]]) {ret += T[s[i]];}
else{ret -= T[s[i]];}
}
return ret;
}
❌Variant:
再写个验证罗马数字是否valid function
地图
上面有很多点, 每个点是个object, x, y 坐标都给了, 比如{x: 5, y: 5}
已知 包含所有点的 array, 某一个点,和半径d, 写一个function 返回到这个点的距离小于或等于d 的所有点。
怎么优化。我当时答得是把整个地图分成小的区域,每一小块2d的正方形。然后找这个点所在的方块和周围的几
个方块。这样就不用遍历地图里所有的点了。
按权重返回随机数。
比如{4: 3, 2: 2, 1: 1},就是指4的权为3,2的权为2,1的权为1,那么返回4的概率是3/7
打印经过城市停车站的所有路线。
比如城市0有一个车站X,城市1有A, B两个停车站,2有C, D, E,3有Y。那么从X到Y的所有路线有:
XY 经过1和2时不停车
XAY, XBY 在1停次车
XCY, XDY, XEY 在2停次车
XACY, XADY, XAEY, XBCY, XBDY, XBEY 在1, 2都停次车。
我一开始用在一个城市停的结果加上在两个城市停的结果做,面试官就问我这是一个排列还是组合。我没明白他
的意思,直到他点明其实这是个排列,就是在每个城市选择每个停车站各一次+不停
一个function实现计算器里的undo以及redo功能。
其实就是考数据结构里的stack。最后的拓展题感觉在问system design,问我如果这种undo以及redo操作是用在
占据很大存储空间以及用户量很大的data上该怎么办,我说那就给每个数据加上index,undo以及redo只用在
index上,最后再用index去取数据。。。
Someone’s Summary?
1. Two Sum8. String to Integer (atoi)12. Integer to Roman13. Roman to Integer20. Valid Parentheses21.
Merge Two Sorted Lists23. Merge k Sorted Lists31. Next Permutation33. Search in Rotated Sorted Array34.
Search for a Range39. Combination Sum40. Combination Sum II46. Permutations47. Permutations II50.
Pow(x, n)53. Maximum Subarray56. Merge Intervals57. Insert Interval60. Permutation Sequence62. Unique
Paths63. Unique Paths II65. Valid Number68. Text Justification70. Climbing Stairs72. Edit Distance74. Search
a 2D Matrix75. Sort Colors76. Minimum Window Substring98. Validate Binary Search Tree100. Same
Tree101. Symmetric Tree102. Binary Tree Level Order Traversal103. Binary Tree Zigzag Level Order
Traversal104. Maximum Depth of Binary Tree109. Convert Sorted List to Binary Search Tree126. Word Ladder
II127. Word Ladder135. Candy136. Single Number137. Single Number II139. Word Break140. Word Break
II149. Max Points on a Line150. Evaluate Reverse Polish Notation151. Reverse Words in a String152.
Maximum Product Subarray155. Min Stack156. Binary Tree Upside Down160. Intersection of Two Linked
Lists169. Majority Element170. Two Sum III - Data structure design173. Binary Search Tree Iterator186.
Reverse Words in a String II187. Repeated DNA Sequences189. Rotate Array198. House Robber200. Number
of Islands205. Isomorphic Strings210. Course Schedule II213. House Robber II215. Kth Largest Element in an
Array216. Combination Sum III226. Invert Binary Tree232. Implement Queue using Stacks236. Lowest
Common Ancestor of a Binary Tree238. Product of Array Except Self240. Search a 2D Matrix II243. Shortest
Word Distance244. Shortest Word Distance II245. Shortest Word Distance III254. Factor Combinations256.
Paint House260. Single Number III261. Graph Valid Tree265. Paint House II277. Find the Celebrity295. Find
Median from Data Stream297. Serialize and Deserialize Binary Tree305. Number of Islands II311. Sparse
Matrix Multiplication319. Bulb Switcher337. House Robber III339. Nested List Weight Sum341. Flatten Nested
List Iterator347. Top K Frequent Elements349. Intersection of Two Arrays350. Intersection of Two Arrays II364.
Nested List Weight Sum II366. Find Leaves of Binary Tree367. Valid Perfect Square377. Combination Sum
IV380. Insert Delete GetRandom O(1)381. Insert Delete GetRandom O(1) - Duplicates allowed409. Longest
Palindrome438. Find All Anagrams in a String464. Can I Win.
Not leetcode ones:1. Tournament tree2. Triangle count3.BST insert/delete/find4.Convex hull5.single valid
tree6.四向鍊錶打平7. Max stack all O(1), Mid stack8.N nearest points9. Max palindrome sequence
Leetcode contest
class Solution {
public:
string boldWords(vector<string>& words, string S) {
string ret;
vector<pair<int, int>> pos;
for (string word : words) { //for each word, find all appearances in S
size_t firstpos = S.find(word, 0);
while (firstpos != string::npos) {
pos.push_back({(int)firstpos, -1});
pos.push_back({(int)firstpos + word.size(), 1});
//cout << word << " " << firstpos<< endl;
firstpos = S.find(word, firstpos + 1);
}
}
sort(pos.begin(), pos.end());
int accu = 0;
vector<pair<int, int>> final_pair;
//bool pre_zero = true;
int bold_begin = -1;
for (int i = 0; i < pos.size(); i++){
if (accu == 0) {
bold_begin = pos[i].first;
}
accu += pos[i].second;
if (accu == 0) {
final_pair.push_back({bold_begin,pos[i].first});
//pre_zero
//cout << bold_begin << " " << pos[i].first << endl;
}
}
if (final_pair.empty()) {
return ret;
}
ret = "";
int last = 0;
for (auto boldpair : final_pair) {
cout << ret << " ";
ret = ret + S.substr(last, boldpair.first - last);
//cout << S.substr(last, boldpair.first - last) << " ";
ret = ret + "<b>" + S.substr(boldpair.first, boldpair.second - boldpair.first) + "</b>";
//cout << S.substr(boldpair.first, boldpair.second - boldpair.first) << endl;
last = boldpair.second;
}
ret = ret + S.substr(last);
return ret;
}
};
● Talent: ability to do the work and potential to learn. It's important to understand the process the
candidate uses to go from beginning to end.
● Thinking & problem solving: figuring out the problem, developing solutions and alternatives, decision
making
● Team description and fit: working with others, coaching, collaborating, influencing, training, being
coached
● Organizational fit: pace, level of sophistication, flexibility, etc.
● Motivation: general work-ethic and self-motivation to apply effort to do the work required.
*Tip: Discuss tradeoffs of different systems and migrations that you’ve worked on, and how those were
executed.
*Be ready to discuss your most significant accomplishment, why was it a huge success to you, others on your
team and even the company?
🔴
Simpoint accuracy applying better algorithm.
Geekbench checkpoints.
Emulation platform.
Coding Interviews: T wo of the below interviews will focus on coding questions. Just like in the phone
interview, these will focus on CS fundamentals, data structures, and math (algorithms, graph theory, etc.). You
won’t be given all the information you need to solve the problem. Instead, you’ll need to ask clarifying
questions to identify use cases, edge/corner cases, etc. This is to get a sense of how you approach a problem.
It’s going to be a very interactive interview, so ask a lot of questions and only start implementing your solution
when you feel you have a good understanding of the problem. If you start struggling with your solution, explain
what you did and why so the interviewers are able to give you hints to get you moving along.
- During these interviews, the engineers will be looking for 1) were you able to come up with a working
solution; 2) how complete your code is; 3) cleanliness of code; 4) time to completion; 5) how optimal your
solution was (if they ask you if you can optimize your solution, look at your algorithm).
One of the interviews will focus on technical communication. This will be a deep dive into projects you worked
on, technologies used, and architectural decisions.
Make sure you're able to speak of an interesting/challenging project you worked on and be able to explain
the challenges faced, lessons learned, and technical details. They’ll be looking for excitement or interest in
the projects you worked on because they want to work alongside engineers who are passionate about what
they do.
● Start at a high level explaining the project (why was it needed, what was it used for, who would use it,
etc.), then explain what your team did, then what you were responsible for. Make sure you have a good
understanding of the decisions that were made and a holistic understanding of the work.
● Think about how you would go about helping on-board a new employee to your existing team and
environment and how you would go about helping them understand the ins and outs of your group
and how it integrates with your engineering organization, how do you work with product, and how does
it all fit together?
● Think about how you might do a quick white board illustration around this to help them better
understand as well.
● Architecture will cover problems in end to end design of complex, internet-scale systems with many
requirements, typically requiring tradeoff decisions.
● The focus of this interview will be your ability to understand the problem, consider appropriate
design alternatives, make appropriate tradeoffs, and choose an approach that solves that stated
problem. Ideally, the solution will be extensible t o support likely future requirements and will be
practical to implement and test. They will also be looking for you to demonstrate knowledge of
"standard" technologies, including open source components.
*Watch this video & read this link!
http://www.infoq.com/presentations/linkedin-architecture-stack &
https://www.linkedin.com/pulse/technical-design-interview-guide-success-joey-addona
Lunch (1 hour):
● This is your opportunity to ask well thought out questions about Linkedin and what you know about
Linkedin and what you’d like to know more about
Promote? Team matching? Culture? How the infinity vacation works? Future development??
● Expect to have a leisurely conversation about the newest open-source technologies out there
● Think about what it is that you’re currently passionate about with your current job or what you have
been passionate about in the past with your current company and be clear as to why you feel
Linkedin is a company you’d like to work for
*Lastly, a few more practice problems and soft skills that are being looked for:
Soft Skills:
● Reiterate the questions asked to ensure that what you heard and understood is what the interviewer
meant.
● Talk to the interviewer (I know they’re an engineer) through your thought process while you’re coding
and/or architecting solutions to the questions asked.
● Spend a short period of time to clarify t he requirements before assuming anything.
● Ensure your code on the whiteboard is NOT messy as they will be critical of these types of things
● Read up on some projects Linkedin is working on so that you can have some good questions ready