airbnb 深秋 interview question -updated
airbnb 深秋 interview question -updated
2017 深秋版
一. Disclaim ................................................................................................................................ 3
二. Coding/Design Questions ..................................................................................................... 3
1. Collatz Conjecture .......................................................................................................... 4
2. Implement Queue with Limited Size of Arrays .............................................................. 5
3. List of List (2D List) Iterator .......................................................................................... 7
4. Display Page (Pagination)............................................................................................... 8
5. Calculator ...................................................................................................................... 12
6. Travel Buddy (Buddy List) ........................................................................................... 12
7. File System ................................................................................................................... 15
8. Palindrome Pairs ........................................................................................................... 17
9. Find Median in Large File of Integers .......................................................................... 17
10. IP Range to CIDR ......................................................................................................... 19
11. CSV parser .................................................................................................................... 21
12. Text Justification........................................................................................................... 23
13. Regular Experssion ....................................................................................................... 24
14. Water Drop/ Water Land .............................................................................................. 25
15. Hilbert Curve .............................................................................................................. 28
16. Simulate Diplomacy...................................................................................................... 29
17. Meeting Time ................................................................................................................ 30
18. Round Prices ................................................................................................................. 31
19. Sliding Game (8 Puzzles).............................................................................................. 34
20. Maximum Number a Night You Can Accommodate ................................................... 37
21. Find Case Combinations of a String ............................................................................. 38
22. Menu Combination Sum ............................................................................................... 39
23. K Edit Distance ............................................................................................................. 40
24. Boggle Game ................................................................................................................ 42
25. Minimum Cost with At Most K Stops .......................................................................... 45
26. String Pyramids Transition Matrix ............................................................................... 47
27. Finding Ocean ............................................................................................................... 50
28. Preference List .............................................................................................................. 51
29. Minimum Vertices to Traverse Directed Graph ........................................................... 53
30. 10 Wizards .................................................................................................................... 55
31. Number of Intersected Rectangles ................................................................................ 56
32. echo TCP client ............................................................................................................. 57
33. Guess Number............................................................................................................... 58
34. Tagged as AirBnB at Leetcode ..................................................................................... 61
三. Design questions ................................................................................................................. 61
1. RSS 订阅系统 / Feed System ....................................................................................... 62
2. key value storage........................................................................................................... 62
3. Bank System ................................................................................................................. 62
4. 设计翻译系统............................................................................................................... 63
四. Cross Functional Questions ................................................................................................ 64
一. Disclaim
这些题目是从地里, glassdoor, CSDN, GeekForGeeks等地收集来的。如果有任何建议或问题,请联系
coolguy@一亩三分地。欢迎撒米。
参考链接:
• http://www.1point3acres.com/bbs/forum.php?mod=collection&action=view&ctid=277
• http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=282721
• http://community.bittiger.io/topic/626/airbnb%E9%9D%A2%E7%BB%8F-%E4%B8%8A%E7%AF%
87
• http://community.bittiger.io/topic/627/airbnb%E9%9D%A2%E7%BB%8F-%E4%B8%8B%E7%AF%
87
• https://github.com/jxr041100/system_design
二. Coding/Design Questions
问题的大致分类:
• 数学问题:
§ Collatz Conjecture
• 数据结构:
§ Design Queue with Limited Size of Array
§ List of List (2D List) Iterator
§ Display Page (Pagination)
§ Calculator
§ Travel Buddy (Buddy List)
§ Trie: File System
§ Trie: Palindrome Pairs
o Bit Operations
§ IP Range to CIDR
• Binary Search:
§ Find Median in Large File of Integers
• 状态机或矩阵变化
§ CSV Parser
§ Simulate Diplomacy
§ Water Land
§ Hilbert Curve
§ Text Justification
§ Regular Experssion
• Time Interval
§ Meeting Time
• Greedy
§ Round Numbers
§ A*: Sliding Game
• DP
§ Maximum Number a Night You Can Accommodate
• Permutation/Combination/Search(BFS/DFS):
§ Find Case Combinations of a String
§ Menu Combination Sum
§ K Edit Distance
§ Boggle Game
§ Minimum Cost with At Most K Stops
§ String Pyramids Transition Matrix
• 图论
§ Flood Filling: Finding Ocean
§ Topological Sorting: Preference List
§ Minimum Verticaes to Traverse Directed Graph
§ 有向图最短路径: 10 Wizards
§ Union Find: Number of Intersected Rectangles
• Calling AirBnB Internal Services
§ echo TCP client
§ Guess Number
Coding Exercise:
https://www.hackerrank.com/tests/52d6d0953bddb/357c91cd6d50039a74f53a47501e23d7
https://www.hackerrank.com/tests/9e26m70rtfm/cfa8b776a12fb5661055772b4297e8ca
1. Collatz Conjecture
https://en.wikipedia.org/wiki/Collatz_conjecture
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=273149
比如 7,变换到 1 是如下顺序:7->22->11->34->17->52->26->13->40->20->10->5->16->8->4->2->1, 总
共需要 17 步。
int res = 0;
for (int i = 1; i <= num; i++) {
int t = findSteps(i);
map.put(i, t);
res = Math.max(res, t);
}
return res;
}
Collatz Conjecture
https://www.cs.bu.edu/teaching/c/queue/array/types.html
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=279191
Design a Queue with arrayList, 但是有限制条件, arraylist 的长度最多为 10, queue 不限制长度。
pop, 先看外边的 list 中最后一个 list 的大小, 如果是 1, 删了当前的 list, 返回, 如果不是, 返回当前 list
最后一个元素
push, 和上边相反, 当前最后一个 list 的大小是 10, 就建个新的.
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=215975
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=294918
if (head == fixedSize - 1) {
List<Object> newList = (List<Object>)headList.get(head);
headList.clear();
headList = newList;
head = 0;
}
return num;
}
Leetcode 相似问题:
• Leetcode #251 Flatten 2D Vector
• Leetcode #341 Flatten Nested List Iterator
By calling next repeatedly until hasNext returns false, the order of elements returned by next should be:
[1,2,3,4,5,6].
So the remove() method actually removes the element returned from the next().
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=167190
举个例子:
如果函数被 call 的顺序是这样的:hasnext() getnext() hasnext() getnext() remove()
假设 data 是 [[1,2][3]]
那么返回 true, 1, true, 2, void
data 变为 [[1], [3]]
@Override
public Integer next() {
return colIter.next();
}
@Override
public boolean hasNext() {
while ((colIter == null || !colIter.hasNext()) && rowIter.hasNext())
colIter = rowIter.next().iterator();
return colIter != null && colIter.hasNext();
}
@Override
public void remove() {
while (colIter == null && rowIter.hasNext())
colIter = rowIter.next().iterator();
if (colIter != null)
colIter.remove();
}
}
List of List Iterator
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=278720
You’re given an array of CSV strings representing search results. Results are sorted by a score initially. A
given host may have several listings that show up in these results. Suppose we want to show 12 results
per page, but we don’t want the same host to dominate the results. Write a function that will reorder
the list so that a host shows up at most once on a page if possible, but otherwise preserves the ordering.
Your program should return the new array and print out the results in blocks representing the pages.
Input: An array of csv strings, with sort score number of results per page. example:
"host_id,listing_id,score,city"
"1,28,300.1,San Francisco"
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=299158
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=290914
5
13
1,28,310.6,SF
4,5,204.1,SF
20,7,203.2,Oakland
6,8,202.2,SF
6,10,199.1,SF
1,16,190.4,SF
6,29,185.2,SF
7,20,180.1,SF
6,21,162.1,SF
2,18,161.2,SF
2,30,149.1,SF
3,76,146.2,SF
2,14,141.1,San Jose
6,10,199.1,SF
1,16,190.4,SF
2,18,161.2,SF
3,76,146.2,SF
6,29,185.2,SF -- 这时不得不重复了,从原有队列拉出第一个
6,21,162.1,SF
2,30,149.1,SF
2,14,141.1,San Jose
先找不同 host ID 的 post,填到一页里,如果找不到不同 host ID 的 post,就从开头顺序拉取,填满
为止。就这样简单,不要想太复杂!
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=298030
做题界面讲的非常详细,还举了几个例子,如果你面经读不懂题的话,做题的时候读也是肯定能
读懂的。比如 1,2,3,1,1,2,2,每一页要填 5 个数,第一页不重复的只能填 1,2,3,没填满怎么办
(怎么办),那就从剩余的数里面依次放进去两个补满,第一页就变成 1,2,3,1,1 就好了。
http://www.1point3acres.com/bbs/thread-297778-1-1.html
http://blog.csdn.net/whuwangyi/article/details/43600839
这题的思路不难,但是实现起来还是有点难度的。在遍历的时候需要维护一个 LinkedHashMap 作
为 page 并且完成去重。用 LinkedHashMap 的好处是可以保证所有的 entry 是按插入的顺序排序
的,所以仍然可以保证按 score 排序的性质。另外,一旦遇到相同的 host_id,则将其对应的行存
到另一个 buffer 里。由于需要变遍历边增减容器里的数据,需要用 ListIterator,并调用 remove 和
add 方法。之前只用过 remove,从来没用过 add。
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=234655
给你一组数据,和每页的容量,要求每页上力求没有重复的 ID 例子:
input:1,2,3,4,1,5,1,2,3,1,3 ; page size : 5
output:
1,2,3,4,5 / 1,2,3,1,1 / 3
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=300128
if (visited.size() == pageSize) {
visited.clear();
reachEnd = false;
if (!input.isEmpty()) {
res.add(" ");
}
iter = input.iterator();
}
if (!iter.hasNext()) {
iter = input.iterator();
reachEnd = true;
}
}
return res;
}
Display Page (解法一)
if (counter == pageSize) {
if (!input.isEmpty())
res.add(" ");
set.clear();
counter = 0;
reachEnd = false;
iter = input.iterator();
}
if (!iter.hasNext()) {
reachEnd = true;
iter = input.iterator();
}
}
return res;
}
Display Page (解法二)
5. Calculator
Leetcode 相似问题:
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=214074
每个人都有一些想去的city,如果你想去的city和另一个人想去的city的相似度高于 50%的话你们就
是travel buddy,叫你ouput一个list of travel buddy按相似度从高往低排序
我没有用倒排序哎,直接用 hashset 存自己的然后历遍一遍别人的就可以了吧。。面试官也认可
的.
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=218938
followup是给了一个max值,找出你的buddy的wishlist里不在你的wishlist里的最多max个城市,根
据buddy和你的重合程度来排序
例如 你的wishlist是 a,b,c,d
问题是输出一个size最多为max的推荐城市列表 当size为10时,buddy1和buddy2的wishlist中不在你
的wishlist中的城市都可以加入推荐中,因为buddy2的重合度更高,所以先输出buddy2中的,所以
推荐为 g,e,f
当size为2时,推荐是g,e 或 g,f
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=278915
followup: recommend at mos k cities. solution: iterate over the city list of the the ranked buddy list from
the first question, output it if it is not already output
int i = 0;
while (k > 0 && i < buddies.size()) {
Set<String> diff = new HashSet<>(buddies.get(i).wishList);
diff.removeAll(myWishList);
if (diff.size() <= k) {
res.addAll(diff);
k -= diff.size();
i++;
} else {
Iterator<String> it = diff.iterator();
while (k > 0) {
res.add(it.next());
k--;
}
}
}
return res;
}
@Override
public int compareTo(Buddy that) {
return that.similarity - this.similarity;
}
}
}
Travel Buddy
7. File System
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=215056
比如 watch("/a",System.out.println("yes"))
watch("/a/b",System.out.println("no"))
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=215981
让你实现一个长成这样的tree:
root
/ \
NA EU
/ \
CA US
其中root是没有name和value,剩下的每个点都有name和value.
• create(path,value):给你一个path,比如“NA/MX”,和value,比如“3”。 那么你就在NA下面
创建一个点叫MX,值是3。
• set_value(path, value): 给你一个path,找到path的叶子,然后set value,如果 叶子不存在,
返回false;
• get_value(path): 给你一个path,返回叶子的值,没有叶子的话返回NULL。
public Solution() {
this.pathMap = new HashMap<>();
this.callbackMap = new HashMap<>();
this.pathMap.put("", 0);
}
pathMap.put(path, value);
return true;
}
pathMap.put(path, value);
// Trigger callbacks
String curPath = path;
while (curPath.length() > 0) {
if (callbackMap.containsKey(curPath)) {
callbackMap.get(curPath).run();
}
int lastSlashIndex = path.lastIndexOf("/");
curPath = curPath.substring(0, lastSlashIndex);
}
return true;
}
8. Palindrome Pairs
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=143760
这种。
正确的普通做法是,把每个词的倒序放进一个hashset,然后枚举每词word :
一个)
二个)
更好的做法是用trie加速枚举,这样一旦trie里面找不到了就不用枚举更长的前/后缀了。但是时间
复杂度是一样的,是O(NL^2),L是平均长度.
Leetcode 上有很好的解法。
Leetcode 相似问题 Leetcode #295 Find Median from Data Stream LC 这道题是 stream input,是没有办
法做 binary search 的。
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=171676
if (count == k) {
return res;
} else if (count < k) {
return search(nums, k, Math.max(res + 1, guess), right);
} else {
return search(nums, k, left, res);
}
}
if (len % 2 == 1) {
return (double) search(nums, len / 2 + 1, Integer.MIN_VALUE,
Integer.MAX_VALUE);
} else {
return (double) (search(nums, len / 2, Integer.MIN_VALUE,
Integer.MAX_VALUE) +
search(nums, len / 2 + 1, Integer.MIN_VALUE,
Integer.MAX_VALUE)) / 2;
}
}
}
Find Median from Large File of Integers
这个是背景介绍: https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing
这个是个 online 转化工具 http://www.ipaddressguide.com/cidr
大概的思路是 group as much IPs as you can. 描述起来还真的麻烦呢,建议跑几个 case,就理解了
code: http://stackoverflow.com/questio ... nge-to-cidr-in-java, 叶泰航给的那个
表达是: ip地址/掩码位数 表示一个区间
然后给你一个起始ip,和数量。用最少的cidr表示这个区间 Examples:
Given a string ip and number n, print all cidr addresses that cover that range - This is one of the
problems that is out of left field.
Given an IPv4 IP address p and an integer n, return a list of CIDR strings that most succinctly represents
the range of IP addresses from p to (p + n).
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=282139
算法:
从一个简单的例子开始:
比如 IP 地址范围是 0.0.0.111 - 0.0.0.120,对应的二进制表示如下
1101111 - 111
1110000 - 112
...
1110111 - 119
1111000 - 120
显然 0.0.0.(11000000)/24 可以覆盖整个地址区间。但是这个 CIDR 不是一个“合格”的 CIDR,因为它
的范围太大了,超出了输入的 IP 地址范围,所以我们要进一步缩小。
return (ip[0] << 24) + (ip[1] << 16) + (ip[2] << 8) + ip[3];
}
return sb.toString();
}
// why max?
// if the currRangeMask is larger than curMask
// which means the numbers of IPs from start to end is smaller
than mask range
// so we can't use as many as bits we want to mask the start IP
to avoid exceed the end IP
// Otherwise, if currRangeMask is smaller than curMask, which
means number of IPs is larger than mask range
// in this case we can use curMask to mask as many as IPs from
start we want.
curMask = Math.max(currRangeMask, curMask);
// Add to results
String ip = longToIP(start);
res.add(ip + "/" + curMask);
// We have already included 2^(32 - curMask) numbers of IP into
result
// So the next roundUp start must insert that number
start += Math.pow(2, (32 - curMask));
}
return res;
}
}
IP Range to CIDR
11. CSV parser
Input: csvformat
John,Smith,[email protected],Los Angeles,1
Jane,Roberts,[email protected],"San Francisco, CA",0
"Alexandra ""Alex""",Menendez,[email protected],Miami,1 """Alexandra Alex"""
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=154363
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=131724
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=140445
可以考虑画一下状态图:
public String parseCSV(String str) {
List<String> res = new ArrayList<>();
boolean inQuote = false;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < str.length(); i++) {
if (inQuote) {
if (str.charAt(i) == '\"') {
if (i < str.length() - 1 && str.charAt(i + 1) == '\"') {
sb.append("\"");
i++;
} else {
inQuote = false;
}
} else {
sb.append(str.charAt(i));
}
} else {
if (str.charAt(i) == '\"') {
inQuote = true;
} else if (str.charAt(i) == ',') {
res.add(sb.toString());
sb.setLength(0);
} else {
sb.append(str.charAt(i));
}
}
}
if (sb.length() > 0) {
res.add(sb.toString());
}
return String.join("|", res);
}
CSV Parser
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=299301
Given a JSON input with a list of strings, e.g.. more info on 1point3acres.com
{
‘text’: 'first word',
‘text’: 'my second sentence',
‘text’: ’now it's third‘,
}.
要求 print 出来这样的形式(格式崩了,大家意会即可,左右间距以最长 str 为准)
+-----------------------+
|first word |
+-----------------------+
|my second sentence |
+-----------------------+
|now it's third |
+-----------------------+
和小哥大致讨论了下,秒了。
然后小哥来了个 follow up, 说 input JSON 里再加一个 width, 要求左右间距以 width 为准,左缩进,
print 出来大概这样:
+----------------+
|first word |
+----------------+
|my second |
|sentence |
+----------------+
|now it's third |
+----------------+
又秒了。
之后小哥说奥森!但还有个 follow up,这回你不用写 code 了,大致说下想法就好:input JSON 为
list of lists, 一级 list 表示一行,二级 list 表示每行中的一列,每列规定 width(相当于每个 string 都
会有自己的 width), print 出来大概这样:
+--------------+----------+
|first word |my |
| |second |
| |sentence |
+--------------+----------+
|now it's third |
+-------------------------+
Leetcode 上有很好的解法。
Leetcode 相似问题:
https://www.mitbbs.com/article_t/JobHunting/33067863.html
是leetcode上面wildcard和regex match的综合,加了+号,大家有啥好方法吗?
• *: 0个或多个之前字符
• .: 任何字符
• +:1个或多个之前字符
另外一点不太清楚是这个加号的作用,如果是 aa 和 +a 这种算是match到了吗?就是加号前面是
空。
应该是 a+吧
https://www.glassdoor.com/Interview/1-find-all-the-combinations-of-a-string-in-lowercase-and-
uppercase-For-example-string-ab-and-gt-ab-Ab-aB-AB-QTN_582954.htm
Implement a simple regex parser which, given a string and a pattern, returns a boolean indicating
whether the input matches the pattern. By simple, we mean that the regex can only contain special
character: * (star), . (dot), + (plus). The star means what you'd expect, that there will be zero or more of
previous character in that place in the pattern. The dot means any character for that position. The plus
means one or more of previous character in that place in the pattern.
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=218383
Example:
int[] 海拔 {5,4,2,1,2,3,2,1,0,1,2,4}
+
++ +
++ + ++
+++ +++ ++
++++++++ +++
++++++++++++
012345678901
+
++ +
++www+ ++
+++w+++www++
++++++++w+++
++++++++++++
012345678901
请问水滴下来。是忘左边走还是右边走呢。还是说我可以假设所有的水滴掉下来都优先往左边
走。直到遇见了不能存储的情况才考虑右边?
都可以 我假设往左先面试官说可以的
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=279000
这个题目比较open-ended。关键是和interviewer讲清楚你的assumption。
我的assumption:
• handle the water drop by drop。 there are infinitely high walls on the left and right
• 水先向左走,走到不能走为止。call it leftMost
• 如果leftmost的水比开始点低,leftMost水+1,done
• 如果leftmost的水不比开始点低,水向右走,走到不能走为止。call it rightMost
• 如果rightmost的水比开始点低,rightMost水+1,done
• 如果rightmost的水不比开始点低,leftMost水+1,done
这道题是这样,很多东西都是很面试官确认出来,像我和他讨论出的结果就有:水滴优先往左
流,没地流再往右流,也没地了就在当前位置涨;两边有无限高的墙挡着;水滴是一滴一滴的,
不能分为小数,所以一滴水会一直往左走到尽头(其实是不符合物理规则的但理他呢。。)
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=229065
输入有一个int数组代表地表的高度,一个下雨的位置,水的总量,要求print出一 个图(+表示土
地,W表示水)显示下雨后水的积存情况。
类似
+W+
+++
char[][] simulateWaterDrop(int[] input, int pos, int volume). 需要一滴一滴模拟,每滴水要找左右两边
的peak,有几种case,分开考虑一下, 完成一滴水之后,再更新高度。
pourLocation = location;
waters[pourLocation]++;
water--;
}
print(heights, waters);
}
int maxHeight = 0;
for (int i = 0; i < n; i++) {
maxHeight = Math.max(maxHeight, heights[i] + waters[i]);
}
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=146537
https://en.wikipedia.org/wiki/Hilbert_curve
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=220456
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=229065
输入是坐标 x,y,还是第几 iteration,输出是从原点走多少步达到这个点。
结合 code,先把 iteration 1,2,3 画出来,就知道是干什么的了,对了,如果可能,也可以试试
反着来一遍。输入是第几 iteration,steps,返回坐标
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=218196
Also known as OA 4
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=298214
总体理解题意以后算法是蛮直接的,没什么技巧,祝大家都好运!
所以这题两个 strength 相等是都挂,但原游戏其实是都撤退?
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=146537
这题最简单的方法就是把所有区间都拆成两个点,然后排序,然后扫描,每次碰到一个点如果是
左端点就把 busy_employees 加 1,否则减 1,等到每次 busy_employees 为 0 时就是一个新的区
间。这样复杂度 O(MlogM),M 是总共区间数。
@Override
public int compareTo(Point that) {
if (this.time != that.time || this.isStart == that.isStart) {
return this.time - that.time;
} else {
return this.isStart ? -1 : 1;
}
}
}
int count = 0;
Integer availableStart = null;
for (int i = 0; i < points.size(); i++) {
Point point = points.get(i);
if (point.isStart) {
count++;
if (availableStart == null && i == 0 && count <=
intervals.size() - k) {
availableStart = point.time;
} else if (availableStart != null && count ==
intervals.size() - k + 1) {
res.add(new Interval(availableStart, point.time));
availableStart = null;
}
} else {
count--;
if (count == intervals.size() - k && i < points.size() - 1)
{
availableStart = point.time;
} else if (availableStart != null && i == points.size() - 1
&& count <= intervals.size() - k) {
res.add(new Interval(availableStart, point.time));
availableStart = null;
}
}
}
return res;
}
}
Meeting Time
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=146539
公司 list 价格分成好几个部分,但是都是整数,如果在美金是整数,到了欧洲的网页显示汇率转
换之后就变成了 floating point,然后要 round 成整数,但是全部加起来 round,和单独 round 再加
起来,结果会不一样
# base price 100 => 131.13 => 131
# cleaning fee 20 => 26.23 => 26
# service fee 10 => 13.54 => 14
# tax 5 => 6.5 => 7
# => 177.4E => 178E
# sum 135$ => 178.93E => 179E
举例
# A = [1.2, 2.3, 3.4]
# Round(1.2 + 2.3 + 3.4) = 6.9 => 7
# 1 + 2 + 3 => 6
# 0.2 + 0.3 + 0.4 = 1.0
# 1 + 3 + 3 => 7
# 0.2 + 0.7 + 0.4 = 1.3
# 1 + 2 + 4 => 7
# 0.2 + 0.3 + 0.6 = 1.1
所以[1,2,4]比[1,3,3]要好
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=156061
Given an array of numbers A = [x1, x2, ..., xn] and T = Round(x1+x2+... +xn). We want to find a way to
round each element in A such that after rounding we get a new array B = [y1, y2, ...., yn] such that
y1+y2+...+yn = T where yi = Floor(xi) or Ceil(xi), ceiling or floor of xi.
贪心应该就可以解决
先对每个 element 进行 round(向最小的那边进行 round ceil 或者 floor)
然后把值加起来 如果和 T 有个差值 比 T 大或者小 X
class NumWithDiff {
int num;
double diffWithCeil;
You're given a 3x3 board of a tile puzzle, with 8 tiles numbered 1 to 8, and an empty spot. You can move
any tile adjacent to the empty spot, to the empty spot, creating an empty spot where the tile originally
was. The goal is to find a series of moves that will solve the board, i.e. get [ [1, 2, 3], [4, 5, 6], [7, 8, - ]…
http://www.1point3acres.com/bbs/thread-203769-1-1.html
https://en.wikipedia.org/wiki/15_puzzle
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=291630
基本的深搜和广搜的性能都非常差,一般使用 A* 或者 IDA*算法
public class Solution {
private final int[][] dirs = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
private int[][] matrix;
private int m;
private int n;
private int originX;
private int originY;
private String recovered;
recoveredMatrix[i][j] = i * n + j;
}
}
this.recovered = getMatrixString(recoveredMatrix);
}
public boolean canSolve() {
Queue<int[]> items = new LinkedList<>();
Queue<String> matrix = new LinkedList<>();
Set<String> visited = new HashSet<>();
while (!items.isEmpty()) {
int size = items.size();
for (int i = 0; i < size; i++) {
int[] curElement = items.poll();
String curMatrixString = matrix.poll();
int x = curElement[0];
int y = curElement[1];
if (curMatrixString.equals(recovered)) {
return true;
}
int[][] newMatrix =
recoverMatrixString(curMatrixString);
int temp = newMatrix[x][y];
newMatrix[x][y] = newMatrix[xx][yy];
newMatrix[xx][yy] = temp;
String newMatrixString = getMatrixString(newMatrix);
if (visited.contains(newMatrixString)) {
continue;
}
return false;
}
while (!items.isEmpty()) {
int size = items.size();
for (int i = 0; i < size; i++) {
int[] curElement = items.poll();
String curMatrixString = matrix.poll();
List<String> curPath = path.poll();
int x = curElement[0];
int y = curElement[1];
if (curMatrixString.equals(recovered)) {
return curPath;
}
int[][] newMatrix =
recoverMatrixString(curMatrixString);
int temp = newMatrix[x][y];
newMatrix[x][y] = newMatrix[xx][yy];
newMatrix[xx][yy] = temp;
String newMatrixString = getMatrixString(newMatrix);
if (visited.contains(newMatrixString)) {
continue;
}
Provide a set of positive integers (an array of integers). Each integer represents number of nights user
request on Airbnb.com. If you are a host, you need to design and implement an algorithm to find out the
maximum number a night you can accommodate. The constrain is that you have to reserve at least one
day between each request, so that you have time to clean the room.
Given a set of numbers in an array which represent number of consecutive days of AirBnB reservation
requested, as a host, pick the sequence which maximizes the number of days of occupancy, at the same
time, leaving at least 1 day gap in between bookings for cleaning. Problem reduces to finding max-sum
of non-consecutive array elements.
// [5, 1, 1, 5] => 10
// Dec 1 – 5
// Dec 5 – 6
// Dec 6 – 7
// Dec 7 - 12
The answer would be to pick dec 1-5 (5 days) and then pick dec 7-12 for a total of 10 days of occupancy,
at the same time, leaving at least 1 day gap for cleaning between reservations.
Similarly,
// [3, 6, 4] => 7
// [4, 10, 3, 1, 5] => 15
转移方程:
• f(0) = nums[0]
• f(1) = max(num[0], num[1])
• f(k) = max( f(k-2) + nums[k], f(k-1) )
return f2;
}
Maximum Number a Night You Can Accommodate
Leetcode 相似问题
https://www.glassdoor.com/Interview/1-find-all-the-combinations-of-a-string-in-lowercase-and-
uppercase-For-example-string-ab-and-gt-ab-Ab-aB-AB-QTN_582954.htm
Find all the combinations of a string in lowercase and uppercase. For example, string "ab" >>> "ab",
"Ab", "aB", "AB". So, you will have 2^n (n = number of chars in the string) output strings. The goal is for
you to test each of these strings and see if it matchs a hidden string.
http://www.1point3acres.com/bbs/thread-289032-1-1.html
给你一个菜单,要你输出一个金额所有能点的不同组 合。要求用完所有钱。
Given a menu (list of items prices), find all possible combinations of items that sum a particular value K.
(A variation of the typical 2sum/Nsum questions).
Return the coins combination with the minimum number of coins. Time complexity O(MN), where M is
the target value and N is the number of distinct coins. Space complexity O(M).
不过这里着重强调这里有一个小坑!!! 之前帖子的人没见人提过,是都没掉里面么??? 就是
说 有一个 interface (vector prices, double total) 这里无论你是使用何种algo,都逃脱不了的是 累加
之后并比较。这里因为是 double类型的累加, 所以在 register 处理的时候会因为为了保证对其,
而对二进制进行变化(当然不是每个double都会出现这种情况)。 这也是double/float 类型在操作
的过程中的问题。没办法保证精度(有特殊的方法进行处理,不过这里不需要考虑) 举个栗子:
double a = 1.5, b = 1.1213; double c = 2.6213; 这个时候 a+b-c 是不等于0的 具体的理解请会议
computer arch。 哎。。。其实当时这里想到了这个原因,不过因为最近收到了一个感觉还不错的
offer 面试的时候就变的懒了 这里就没提问。 当然也没想到这个小坑竟然把我挂了。。。 正确的
过程是,面对这种需要考虑精度的问题 在一开始就要问面试官,精度要求多少 然后在最后求解的
时候 给出这样的判断方式 (abs(a+b-c) < 0.0000001) 之类的。 或是 干脆对每个数字都乘以一个
大的数,比如都乘以10000。 不过注意不要溢出。。。
Leetcode 相似问题:
Find all words from a dictionary that are k edit distance away.
return res;
}
class TrieNode {
TrieNode[] children;
boolean isLeaf;
public TrieNode() {
children = new TrieNode[26];
}
}
class Trie {
TrieNode root;
public Trie() {
root = new TrieNode();
}
TrieNode p = root;
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (p.children[c - 'a'] == null) {
p.children[c - 'a'] = new TrieNode();
}
if (i == s.length() - 1) {
p.children[c - 'a'].isLeaf = true;
}
p = p.children[c - 'a'];
}
}
}
}
K Edit Distance
http://www.1point3acres.com/bbs/thread-191416-1-1.html
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=158462
http://www.1point3acres.com/bbs/thread-220456-1-1.html
这题真的好蛋疼啊,首先你要找出一个单词所有可能出现的位置序列,然后根据每个单词出现的
序列在分别做 DFS,分别是不取这个单词,取第一个序列,取第二个序列,etc。
http://www.1point3acres.com/bbs/thread-158462-1-1.html
int m = board.length;
int n = board[0].length;
visited[xx][yy] = true;
curPath.add(new int[] { xx, yy });
search(paths, board, xx, yy, trie, visited, curPath);
curPath.remove(curPath.size() - 1);
visited[xx][yy] = false;
}
}
if (canUse) {
for (int[] coor : paths.get(i)) {
visited[coor[0]][coor[1]] = true;
}
curWords.add(path2Word(board, paths.get(i)));
searchWords(res, curWords, paths, i + 1, visited, board);
curWords.remove(curWords.size() - 1);
for (int[] coor : paths.get(i)) {
visited[coor[0]][coor[1]] = false;
}
}
}
}
int m = board.length;
int n = board[0].length;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
boolean[][] visited = new boolean[m][n];
visited[i][j] = true;
List<int[]> curPath = new ArrayList<>();
curPath.add(new int[] { i, j });
search(paths, board, i, j, trie, visited, curPath);
}
}
return res;
}
class ReturnType {
boolean hasPrefix;
boolean hasWord;
ReturnType(boolean hasPrefix, boolean hasWord) {
this.hasPrefix = hasPrefix;
this.hasWord = hasWord;
}
}
class TrieNode {
char c;
boolean isEnd;
Map<Character, TrieNode> children;
public TrieNode(char c, boolean isEnd) {
this.c = c;
this.isEnd = isEnd;
this.children = new HashMap<>();
}
}
class Trie {
private TrieNode root;
public Trie() {
this.root = new TrieNode(' ', false);
}
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=215824
给定很多航班信息,至多k stop,找最便宜路线. 给很多 tuple <depart city, dest city, cost> 代表flight,
找出 给订 city A, city B, maxStops, 最小cost的path
Given a flight itinerary consisting of starting city, destination city, and ticket price (2d list) - find the
optimal price flight path to get from start to destination. (A variation of Dynamic Programming Shortest
Path)
Output list of strings representing a page of hostings given a list of CSV strings.
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=220456
if (curr.name.equals(target)) {
find = true;
continue;
}
Given a list of leaf nodes in a pyramid, and a map which indicates what's the possible parent node given
a left and right node. Return true if the one of leaf node could turn into the root node, Otherwise, return
false.
Example:
root
/ \
X X
/\ /\
X X X
/ \/ \/ \
A B C D
Map:
left: A | B | C | D
right---------------------------------
A B |A or C| D | A
B D |B or C| A |
C B
D
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=212660
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=146537
或者
C
AB
CCA
ABCC
等等。
现在要求给一个这样的表,一个初始字符串和终止结果(字母),要求反悔有没有可能
从初始字符串推到给定的终止结果。
比如 ABCC, A。则返回 true
AC, B。则返回 false。
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=293594
由于转化矩阵和合法终点都是固定的,那么设计一个类里面有个<string, bool> 的 map 确定当前字
符串是 yes or no, 然后每一次 call check_string 的时候就会存储多条 true or false 的 string 到 map 里
面,从而使得以后的 call check_string 如果能碰到一样的串就不用继续 recursion 了。
Solution(String[] line) {
cache = new HashMap<>();
map = new HashMap<>();
for (String s : line) {
String[] splitted = s.split(",");
String key = splitted[0] + SEP + splitted[1];
Set<Character> set = new HashSet<>();
for (char c : splitted[2].toCharArray())
set.add(c);
map.put(key, set);
}
}
return false;
}
Leetcode 相似问题:
• Leetocde #200 Number of Islands
• Leetocde #305 Number of Islands II
• Leetocde #694 Number of Distinct Islands
• Leetocde #711 Number of Distinct Islands
• Leetocde #695 Max area of Islands
• Leetcode #463 Island Perimeter
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=141746
/**
* Given: An array of strings where L indicates land and W indicates water,
* and a coordinate marking a starting point in the middle of the ocean.
*
* Challenge: Find and mark the ocean in the map by changing appropriate Ws to Os.
* An ocean coordinate is defined to be the initial coordinate if a W, and
* any coordinate directly adjacent to any other ocean coordinate.
*
* void findOcean(String[] map, int row, int column);
*
* String[] map = new String[]{
* "WWWLLLW",
* "WWLLLWW",
* "WLLLLWW"
* };
* printMap(map);
*
* STDOUT:
* WWWLLLW
* WWLLLWW
* WLLLLWW
*
* findOcean(map, 0, 1);
*
* printMap(map);
*
* STDOUT:
* OOOLLLW
* OOLLLWW
* OLLLLWW
*/
while (!queue.isEmpty()) {
int pos = queue.poll();
int m = pos / board[0].length;
int n = pos % board[0].length;
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=218938
也是地里出现过的了,每个人都有一个preference的排序,在不违反每个人的 preference的情况下
得到总体的preference的排序
[2, 3, 5, 8, 7, 9]
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=273389
不过好像觉得有 circle 的时候不太知道怎么处理,比如边是[[0, 1], [1, 0], [3, 1], [3, 2], [2, 1]] 的时候
我是每次 DFS 的时候另外用了个 unordered_set 记了一下都见过了什么 要是[[0, 1], [1, 0], [3, 1], [3,
2], [2, 1]]
假设从左到右 process 第一次 set 里就只有 0 跟 1 然后接着 process [1, 0]这个已经在 map 里了直
接跳过 [3, 1]没在 map 里所以 DFS 最后 set 里有 3210,也就是说 DFS 里又见到[1, 0]是不跳过的
思路:
1.处理(一个头,两个头)找所有入度为零的点,全加到 result 集,对每一个点 dfs 或者 bfs 皆
可,然后用一个 set 存所有没访问过的点,遇到即从 set 中删除
2.剩下的就是无头的环,继续 dfs/bfs 剩下的 set 中的点,直到 set 为空,每次 dfs 前把开始的点加
到 result 里(注意 set 的 concurrent modification error)
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=212885
0 1 2 3 4 5 6 7 8 9
0[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
1[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
2[0, 0, 0 ,0, 0, 0, 0, 0, 0, 1],
3[0, 0, 0, 1, 0, 1, 0, 1, 0, 0],
4[0, 0, 0, 0, 0, 0 ,0, 0, 1, 0],
5[0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
6[0, 0, 0, 0, 0, 0, 1, 0, 0 ,0],
7[0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
8[0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
9[0, 0, 0, 1, 0, 0, 1, 0, 0, 0]
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=220456
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=277494
There are 10 wizards, 0-9, you are given a list that each entry is a list of wizards known by wizard. Define
the cost between wizards and wizard as square of different of i and j. To find the min cost between 0
and 9.
巫师不同级别,算最小路径. 有向图里面找最短路径
抽象一下,典型的 djstra 问题
BFS 是可以做的,时间复杂度比 Dijkstra 还小
如果保证 wizard 认识关系双向的话,最优路径不会回头,一个简单 dp 就可以了,线性复杂度。
不保证的话,选一种最短路算法实现,顺手就行。 Dijkstra m*log(n).
楼上的 bfs 算法会退化,别的先不说,一个点在队列里出现两次是没有意义的。(补上了还是会
退化。)
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=278915
想请教下魔法师这道题,我没太明白题目含义:
简化下比如说有五个魔法师,求 0 到 4 认识的最少距离
0 号认识 1 号和 2 号
1 号认识 3 号
2 号认识 3 号,4 号
3 号认识 4 号
多问一句,这个是无向图还是有向图?我理解的认识的话,是两个人都互相认识,对吗?谢谢!
我面试时,面试官没有提到“初始巫师本来就认识的那些巫师不需要收费”,所以你的例子要加上
(2-0)^2.但是我觉得这一点对解法没有影响。
我是根据无向来理解。
map.get(source).dist = 0;
Queue<Wizard> pq = new PriorityQueue<>(n);
pq.offer(map.get(source));
while (!pq.isEmpty()) {
Wizard curr = pq.poll();
List<Integer> neighbors = wizards.get(curr.id);
for (int neighbor : neighbors) {
Wizard next = map.get(neighbor);
int weight = (int) Math.pow(next.id - curr.id, 2);
if (curr.dist + weight < next.dist) {
parent[next.id] = curr.id;
pq.remove(next);
next.dist = curr.dist + weight;
pq.offer(next);
}
}
}
You have a plain with lots of rectangles on it, find out how many of them intersect.
if (root1 != root2) {
parents[root1] = root2;
}
}
}
}
return set.size();
}
}
Number of Intersected Rectangles
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=165457
client向server发的请求有以下2种:
EXAMPLE: 比如在telnet中
STATUS
0.0 0.0 (这行是server返回的,第一个数字表示压力,第二个数字表示速度)
THROTTLE 50.1 (这个指令发出 server没有返回)
STATUS
50.1 3.75
STATUS
50.1 15.98
对就是这样,像是简单物理实验。写完TCP client后,要求是写一个方法将速度控制到达一个target
speed 我当时写的是直接最大值,等到了目标值之后再二分
老师了。。。。。。时间不够了
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=148195
加速度公式
Vt^2-Vo^2=2as
一个物体做匀加速运动经过一段距离 S。则末速度的平方减初速度的平方等于距离乘以加速度的 2
倍。
Va=(Vo+Vt)/2=V(t/2)
平均速度等于初速度与末速度的平均数,也等于 t/2 时刻的瞬时速度。
S2-S1=at^2
一个物体做匀加速直线运动,在两段连续且相等的时刻内通过的距离分别是 S1,S2,则两端距离的
差等于 at^2
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=189016
猜数字
猜一个4位的数字,每位上数字从1到6.
提供一个API,输入一个你猜的数字,返回有几位是猜对的。
比如要猜的数字是1234,猜的数字是1111,则返回1
猜的数字是1212,则返回2
要求写个程序多次调用这个API以后,返回猜的数字结果是什么.
1111,2222,3333,4444,5555
5 次找出 4 个数字 6666 不用找,因为 guess(6666) = 4 - ( guess(1111)+...+guess(5555) )
然后试
a1a1a1a1, a1a2a2a2, a1a3a3a3 同理 a1a4a4a4 不用试
目的是找出后三个数的数字组合 (不是排列)
找出后 3 个数字 就确定了第一个数字,而且这一轮 a1a1a1a1 不用调 api,第一轮里有
第二轮 2 次: 固定第一个数字,找到后 3 个数字组合
更正一下:目前能想到最好 5+2+1 = 8 次
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=290126
要猜出一四位数字。
例子:
# correct code: 3264
# GUESS 1111 => 0 0 (no correct digits
# GUESS 1214 => 2 0 (digits 2 and 4 are correct and on correct position)
# GUESS 6111 => 0 1 (digit 6 is present, but on a different position)
# GUESS 6211 => 1 1 (digit 2 is not counted towards the second count!)
写的时候要连到一个 server 上。
# START\n
# GUESS 1111\n =>0 0
# etc......
没看到过面经,几经提示答出来了。隔天说过了。
三. Design questions
1. RSS 订阅系统 / Feed System
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=295447
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=299066
3. Bank System
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=304012
面经也提到过,因为他们家支持 26+语言,每次在页面上更改信息或者添加新的页面,都需要生成
不同语言的网页。需要设计一个 micro service,需求是要和 front end decouple,就是 front end
engineer 在更改完页面之后,不需要自己操作,这个 service 就能自行的完成翻译。我就是这一点
没有答好,我想的是,code change 之后总得需要 commit 什么的吧,在那个时候,send request 到
这个 service。面试官表示不能认可。我就不知道如何 decouple from front end。而且最后 feedback
是 high level 都是可以的,但是具体细节不知道怎么实现的。。你们一个内部的 service,问我具体
怎么实现的。。其他部分的设计可以参考这个 link http://nerds.airbnb.com/launching-airbnb-jp/.
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=229065
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=290595
设计是地里的经典老题做翻译系统,要求之前地里同学也提过,就是有三个人,前端工程师,翻
译官和用户的体验都要做好,他用了很久来解释这个题。这题我也是做了很久的准备,包括他们
的 blog 和自己公司的经验。但这个题目和面试官完全无法交流的感觉。可能是因为我没有前端经
验,他上来就问在这个 html 里怎么加一个 service call 然后说不用管 syntax,我想那这不就一行
code call 后端 API 不就行了么,然后给了点参数,他说要包含可翻译的和不可翻译的部分,那我
就加上去了,然后就在 API 应该怎么写这讨论了五分钟,不是说系统怎么 design,就是这一行
code 要怎么写。有一种和小学生讨论的错觉,他问了很多 “这还用说” 这种类型的问题。做过
design 的人都知道,API 设计是一个整体,前中后都要考虑,光说前端应该要什么怎么能 design
好呢?面试官草草说赶快到下一个环节。下一个环节他说你设计一下 schema 好了。说有一个网
站是显示需要翻译的东西的,问你怎么设计 table。那我就说他需要什么我就给什么就好了,直接
一个表里需要的 column 都加上,加了 index 和 composit primary key。他也没问别的。最后就说怎
么能让 user 看翻译的东西更快,假设 network 很慢怎么办。这个时候已经没什么时间了,我也没
考虑太多,给 webserver 后面加了个 cache,然后让 internal network 可以去更新这个 cache 然后
external user 只看 cache 不看别的。现在想想都不知道应该怎么办,当时说 network 再慢也要
make call 吧,我们可以在浏览器 cache 一下翻译的东西能避免新的 call,其他的怎么样都要 call 一
次吧。他还是没说什么,然后就结束了。
因为他们家支持 26+语言,每次在页面上更改信息或者添加新的页面,都需要生成不同语言的网
页。需要设计一个 micro service,需求是要和 front end decouple,就是 front end engineer 在更改完
页面之后,不需要自己操作,这个 service 就能自行的完成翻译。我就是这一点没有答好,我想的
是,code change 之后总得需要 commit 什么的吧,在那个时候,send request 到这个 service。面试
官表示不能认可。我就不知道如何 decouple from front end。而且最后 feedback 是 high level 都是
可以的,但是具体细节不知道怎么实现的。。你们一个内部的 service,问我具体怎么实现的。。
其他部分的设计可以参考这个 link http://nerds.airbnb.com/launching-airbnb-jp/
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=165457
通过只有一个技巧, 他家很有前景,你很喜欢他家的服务,他家的服务能让人更
好的感受local 的文化。
1) what bring you to airbnb?
2) what can you teach your co-woCrkers after you get in?
3) describe a person whom you admire most
4) describe your experience with airbnb
5) where have you been to?
6) what will you do if you win a lottery such as Powerball?
7) what is the biggest fear in your life?
8) how do describe Airbnb to a people back to 2003?
9) if you have a book that writes about your whole life, will you read it? why?
10) if you have a time machine, and you can either go back or go forth, will you choose
to go back or to go forth?
11) among all the features of airbnb, what do you want to improve?
12) 描述一件你当时觉得非常risky 的事情,你是怎么做的,结果如何
13) 描述下你自己的品质和你最admire 的一个人
问题有你觉得气床现在面临哪些挑战,怎样可以克服,你犯过什么错误给他人造成了不好的影响
之类。
问了挺多问题,都是不同角度,很仔细的问了我对airbnb 文化的理解,我对自己
的理解还有我的character 是怎么和airbnb 文化conform 的
中心思想就是我爱旅游, 我喜欢不同的文化, 世界上的恐惧都是不了解造成的。
(我确实爱旅游, 我确实喜欢不同文化) 然后airbnb 的core value 也要看看, 把
自己的经历往那上扯就好。
When working in teams, describe a time you made the biggest sacrifice.
Describe the best team you've worked with.
Describe a company that you think is doing really well and explain why.
Describe one of the creative things you have done recently.
问题有你觉得气床现在面临哪些挑战,怎样可以克服,你犯过什么错误给他人造成
了不好的影响之类
问题有你过去一年有没有很热情的帮助过别人,如果你下一年不愁钱了打算干啥之
类,有没有人对你某个观念转变产生过很大影响。
你想给空气床加什么功能?如果能给空气床减功能,你减什么?你为啥要来空气床,
给俩原因?
做过的最scary的事情?
host的经历?
你对airbnb公司五年内发展的预测?
还有什么其他公司也注重hospitality?
airbnb网站那个feature你觉得没必要?
如果是你你要加什么feature?
问了挺多问题,都是不同角度,很仔细的问了我对airbnb文化的理解,我对自己的
理解还有我的character是怎么和airbnb文化conform的
中心思想就是我爱旅游, 我喜欢不同的文化, 世界上的恐惧都是不了解造成的。
(我确实爱旅游, 我确实喜欢不同文化) 然后airbnb 的core value 也要看看, 把
自己的经历往那上扯就好。
the most hospitable person you met, the biggest trade off in your project.
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=174191