近期Stripe面经总结

高频题

这题的完全解答(6步全)在 第三课:Facebook 与 Bloomberg 专题之OOD 课上给了代码答案


再贴下别人的面经:

今天一大早刚刚做的Stripe电面,一个白人小伙面的,题目是实现Database的老题。幸好看了面筋写的还算流畅。

不过感觉以前的资料写的不太全,自己再稍稍整理一下,算是回报吧。

第一、第二问以及背景: 看前人发的链接就好:
https://gist.github.com/weiqitoby600/fd3db87ae8123432c844fb1601413525

第三问:重写一个新的RecordComparator实现List<Map<String, Integer>> records 的排序,这道题把类的名字,构造函数都写好了,让你写

Compare就好。返回 0/-1/1。

函数:public int compare(Map<String, Integer> left, Map<String, Integer> right){return 0}

第四问:给一个LinkedHashMap<String, Integer>, 每一个都是key 和 direction, 先根据第一个key dir排序,再根据第二个、第三个… 排序。

这道题看以往面经的时候自己理解错了,以为先根据第一个拍,排序完的结果再根据第二排,犯傻了。实际情况是排序是第一个元素相等的序列根据第二个再排一次,自己再写了一个Collections.sort()里面重新定义一个Comparator写好了。排序后返回第一个元素即可。

函数:public String sortFirstByOrder(LinkedHashMap<String, Integer> sortedOrder, List<Map<String, Integer>> records){ return “” }

完后第三、第四问写了一点Test case, 再问我还有什么问题,就结束了。

就这样,我来美国1年半多了,也就第三回电面,没有on site。没大神那么牛逼,手握那么多on site,一个Career fair都有十几个电面。正常的New grads而已。

补充内容 (20181027):

补充说明,我已经挂了。诶,无语。


想问楼主,第四问的时候如果map里没有那个key要怎么办呢?

所有题目,没有那个Key就当作value=0处理


请问楼主step 1需要像前人github上一样写很多其他的方法和类吗,是不是只要写他要求的那一个minByKey方法就 ...

写一个minByKey方法就可以了


Step 4

Time to take this"firstby"

functionality further, to sort by more than one key at atime.

Consider an array of records likethis one:

[{“a”: 1, “b”: 1}, {“a”: 1, “b”: 2}, {“a”: 2, “b”: 1}, {“a”: 2, “b”: 2}]

Using first_by_key with this array ofrecords with key “a” might not give us as much control as we’d likeover the result, since more

than one record has the same value for"a" (similarly for “b”). More generally, we might say"order by the first key, in the first direction.

Break ties according tothe second key, in the second direction. Break remaining ties by the third key,in the third direction, and so on."

Note that the sort direction fordifferent keys need not be the same.

We might represent this ordering witha list of pairs like


[

("a", "asc"),

("b", "asc"),

("c", "desc"),
]

We’ll call this type of representation a sort_order.

You’ll need to write a function first_by_sort_order. It takes two arguments:

a sort_order

an array of records

It returns the first record according to the given sort_order.

As before, we’ll ask that you reimplement your previous functionality (first_by_key) in terms of first_by_sort_order.

Hint: can you construct a “sortorder” comparator using your comparator from the previous step? How might constructing a sort order comparator be helpful?

Java function signature:

public static Map<String, Integer> firstBySortOrder(LinkedHashMap<String, String> sortOrder, List<Map<String, Integer>> records);

Examples (in Python):

assert(
first_by_sort_order(
[("a", "desc")],
[{"a": 5.0}, {"a": 6.0}],
) == {"a": 6.0}
)
assert(
first_by_sort_order(
[("b", "asc"), ("a", "asc")],
[{"a": 5,
"b": 10}, {"a": 4,
"b": 9}],
) == {"a": 4,
"b": 9}
)
assert(
first_by_sort_order(
[("b", "asc"), ("a", "asc")],
[{"a": 5,
"b": 10}, {"a": 4,
"b": 10}],
) == {"a": 5,
"b": 10}
)

onsite

他家题都一样 唯一不同的是 debug 那轮我用的java 题是moshi中next index 的一个

algorithm那 轮的题目是

  1. 输入有一堆account, 包括name, time, due amount, 按照时间给每个人发多封pay due 的提醒邮件,输出所有按时间排序的email

  2. 再给一堆还钱的时间点,还清就不用发提醒邮件了,输出所有email


就和之前面经说的一样,面试官强调说不需要最好的O(n)速度,也允许我查 Java document, 查 Stack Overflow, 就希望我写得快,但题目和论坛里2016的已经不一样了,

有3个follow up。

内容大概就是给一个001010之类的字符串,从左到右扫。

碰到1会扣分,0不扣分,但一共有一次机会可以选择反面,也就是1不扣分而零扣分。

现在给反面的位置,求得分。

例如不使用反面,那就是一共扣 0+0+1+0+1+0=2分。

例如在"001"的1之前使用反面,那就是一共扣 0+0+0+1+0+1=2分。

follow up 1 那只给这个字符串,问哪里使用反面扣分最少。 暴力解,每个位置试一遍。没有研究过更好的解法,面试官也无所谓。

follow up 2 那再给一个带+和-的字符串,只有+和-中间的才算,例如+00+00-00-00-,那只有最中间的"+00-"才算。问这些该从哪里使用反面。followup 2 可以把所有的0/1 提取出来再call followup1 的API就行了。

补充内容 (2019114):

面完马上(3小时内)HR通知下一步了。

补充内容 (2019129)

第二面,HM。面了很多项目细节,问挑战是什么。感觉整个回答都是自己是个傻逼。毕竟没有能够当组里TL。面完挂了。还是自己水平太差

2 Likes

OA和店面总结一下是5题

  1. radar rule
3月24日条带Stripe的OA

周一做完的,今天收到了下一轮VC邀请。
一道代码题一道主观题。题目是地里去年10,11月份的那道题,有一点细微改动写在下面了:
Rader Rule, 改动的地方是只有 == 和 != 但是 rule里空格是optional的,就是可以出现"amount==100" 或者 “amount ==100”, 如果用split() 比如我,就要小心这个,要先用replace把"==" 都换成" == " 然后再split。
13个 样例过了12个,满打满算用完了75分钟。我没有特殊处理过corner case。可能是中间处理方式不同造成的吧。

  1. platform balance
2019 Intern OA

刚做完的stripe oa,75min,一道编程,一道分析
编程题是 给了一个list,包含两种api, "API: "和 "BAL: "
“API” 用来更新账户的banalce
“API: amount=1000&merchant=121212” (这种情况下钱减去手续费,会全部存到merchant)
“API: amount=1000&merchant=121212&destination[account]=123456&destination[amount]=877” (这种情况会钱先分给
destination[account], 剩余的存到merchant)
“BAL” 用来查询
“BAL: merchant=121212”
要求返回所有"BAL"查询的结果
分析题就是如何优化上面的代码。就往系统设计方向答,如何对账户建模,如何处理异常,如何提高安全性这样,你可以参考下。

实习OA 挂经

过了比较奇葩的test5 和 test 12,但是没有过test 8,
注意的地方
a. 推荐用的那个库,URLEncodedUtils 记得还要配合一个namevaluepair的库用
b. test4 确实可能是没有这个merchant就返回0
c. test 5 和 test 12可能是要考虑 只有destination[account]或者只有destination[amount]的情况。只有destination[account] 就是所有钱给merchant, 只有destination[amount]就是要考虑减掉这部分钱
(我记得当时还考虑很多其他情况,如 有没有merchant, 有没有merchant amount,但是好像对test case没啥影响)

  1. missing server
社招店面


第一題可以直接用set(每一個數字的前後 減1 ,加入 set,每個 input數字 比對一下,最後 sort就得到)。不用set可以寫個 priority queue。
第二題應該是 hashmap 和 set,我所指的set,是按第一題input list計算出來

GHC Job Fair - new grad

技术面,自带笔记本,给出一组int数组A,表示机器id(从1)开始,让你找出第一个available的server id给assign给新的一个server,其实就是找first missing number,扫两遍可以做到线性求解,也可以排序后找,但是时间复杂度是O(n log n), 但是面试官在这一步不care效率,只要求快速求解,然后我就用sorting的方式秒了,中间follow up是怎么test,要考虑什么, 答考虑duplicate ids,然后改了下算法处理这个问题。

问题2是上面的提升版,有一组String数组A,element的形式是若干个letter最后跟着几个数字,比如apibox1, apibox2,表示对apibox这个type的server的备份,需要实现String allocate(String type), void deallocate(String name)这两个函数,功能和第一题一样,只不过要针对不同的server type分别处理。第一个版本是HashMap<String, LinkedList>实现,实现的过程中我说这不是最优方式,但是因为要快速实现first version所以先这么写。跑通后开始讨论最优方式,LinkedList部分用一个priorityqueue取代,并且每个server type记录一个upperbound, priorityqueue存的是missing numbers,每次allocate时,取最小的missing number x,如果x == upperbound,再把(x+1)丢到priorityqueue里, upperbound++. priorityqueue直接把当前的id扔到queue里。

deallocate的时候如果需要先查找number是否存在,应该可以用一个HashSet存着哪些number还在, 这样就不用查heap了

社招电面跪经
  1. 给个数组,查找第一个miss的int,从1开始。
>> next_server_number([5, 3, 1]) 2 >> next_server_number([5, 4, 1, 2]) 3 >> next_server_number([3, 2, 1]) 4 >>
next_server_number([2, 3]) 1 >> next_server_number([]) 1
  1. 在此基础上,实现allocate和deallocate两个函数,给定server_type之后要能返回拼出来的hostname。
>> tracker = Tracker.new()>> tracker.allocate("apibox")"apibox1">> tracker.allocate("apibox")"apibox2">>
tracker.deallocate("apibox1")nil>> tracker.allocate("apibox")"apibox1">> tracker.allocate("sitebox")"sitebox1"

第二题用HashMap<String, Set>就够了
题目很简单,Test case要考虑全面,不然会有不少没有考虑到的地方。题目写好并测试完,面试官给了很positive的评价,根本没提到有什么遗漏的地方。

New Grad 店面

面试时两个人视频,共享屏幕。面试可以查资料,可以在IDE上写。
Q1: String allocate(String serverType) 参考leetcode41
Q2: deallocate(String ServerName) 这个serverName 里包含数字,需要用regex解析出来。

  1. score
海投社招视频店面

就和之前面经说的一样,面试官强调说不需要最好的O(n)速度,也允许我查 Java document, 查 Stack Overflow,就希望我写得快

有3个follow up。
内容大概就是给一个001010之类的字符串,从左到右扫。
碰到1会扣分,0不扣分,但一共有一次机会可以选择反面,也就是1不扣分而零扣分。
现在给反面的位置,求得分。
例如不使用反面,那就是一共扣 0+0+1+0+1+0=2分。
例如在"001"的1之前使用反面,那就是一共扣 0+0+0+1+0+1=2分。

follow up 1
那只给这个字符串,问哪里使用反面扣分最少。暴力解,每个位置试一遍。没有研究过更好的解法,面试官也无所谓。
O(n) 解法可以是从左扫一遍得到 leftPresum, 然后从右扫一遍得到 rightPresum, 从右扫的时候翻转一下。

follow up 2 那再给一个带+和-的字符串,只有+和-中间的才算,例如+00+00-00-00-,那只有最中间的"+00-"才算。问这些该从哪里使用反面
可以把所有的0/1 提取出来再call followup1 的API就行了

面完马上(3小时内)HR通知下一步了。
第二面,HM。面了很多项目细节,问挑战是什么。感觉整个回答都是自己是个傻逼。毕竟没有能够当组里TL。面完挂了。还是自己水平太差

  1. rate limiter
校招面经

第一问: 2秒之内只能发5个request, 怎么limit
第二问: 如果request 里面有customer id, 怎么让这个rate limit是customer specific的 (就是 customer 1 的limit超过了 并不影响 customer 2 的 request)
第三问: 有的request 会比其他的request 更 expensive。那么如果 input 里面还有一个关于 request weight 的信息,怎么改这个function。(比如 request 1 要占两个request的位置,怎么改)这个要自己多加一点test case, 就什么limit是 5 request/2s, 那么一个weight 是6 的request就直接fail之类的。

Onsite

社招挂经

第一轮: 找json parse bug。解析json的库,问题在于解析object或是array的时候,index没有+1,所以解析出来的下标不对,在怀疑的地方打log追踪可以找到parse的时候少调一行nextElement

第二轮: 设计一个转账系统。主要是转账,入账和payout,比如有人付了一笔钱,merchant卖完后我们把这笔钱转给merchant。这轮系统设计挂了,应该要有点儿金融经验才知道设计trick在哪里。除了大框架,你要准备数据库设计,支持多种payment,balance计算,atomic transactions, 同时入账出帐请求什么的

第三轮: coding 类似于 https://leetcode.com/problems/time-based-key-value-store/
具体应用就是用户10天前欠了一笔钱,期间用户可能还钱,所以某天发邮件提醒时要找出那天之前用户的操作,以便知道该提醒欠款多少

第四轮: integration request replay。parse一个json file,里面是array of objects, 每个object又包含一个request和一个response,replay request和response 做比较。给的是log,需要自己写class,不过格式一致,所以一个response class就可以,我本说写个基类,然后不同api response extends base class, 他说不用,看log file里只有一种request,response格式。

2 Likes

Is debug on moshi? can point to specific issue or test?

Is debug on moshi for you? do you remember specific issue on github or test where issue present?

moshi 是什么?

which json parsing library debug question on? moshi or something else?

我只是总结了别人的面经,这个我不知道啊

谢谢

再总结几个近期的在职跳槽的店面,new grad其实差不多


好像店面题目换了。。
1 给一个string 0 1 0 0 1 表示server的状态 0 是up 1是dow 给一个remove的时间点 求出penalty 有2条rule:1 如果 out of network时serve的状态是up 则penalty +1 如果in network时是down +1。 in/out network的点是你定的。所以假设server status是[0, 0, 0, 1, 1, 1],如果我在index = 2的地方remove就等于没penalty
2 找到最好的时间点remove server from network。如果在index时选择remove 那么index前的1有penalty index后的0有penalty
3 读取一堆log (begin begin 0 1 end balabala)找到所有valid log的的best remove time
只做了这几步 目测一挂~~


找不到它家内推,直接网申的。申完不到一周就被联系了。

三年多经验。

几分钟前刚电面完条纹家。虽然大体上还是经典的toy database题,但要求似乎有点变化(和LZ之前看到的面经相比)

  1. 测试框架需要自行搭建
  2. 没有给定的signature, 自己定义
  3. 只给了最基本基本测试样例,所有special case 和 edge case的测试需要自己加
    需要从头搭建测试框架这点, 对于Java和C++的同学非常不友好,一大半时间都在搭框架和定义测试样例(搭测试框架25分钟,写
    各种样例5分钟,两个comparator两个method 不到10分钟敲完。。。Java党枯了)。用这两种语言的,准备这道题的时候不光要
    考虑解法,也得想好怎样写测试更快,并选择相应的signature以保证最大限度地节省时间。
    题目放在下面,这个版本的part2其实有点像是之前版本的part2 + part3 + part4综合,只是没有考虑升降序(如果需要考虑升降序的话,comparator里面加一个判断调换个符号就好了)

Write a function minByColumn that takes a database table (as above), along with a
column, and returns the row that contains the minimum value for the given column.
If a row doesn’t have any value for the column, it should behave as though the
value for that column was zero.

Examples

table1 = [
{“a”: 1},
{“a”: 2},
{“a”: 3}
]
minByColumn(table1, “a”) returns {“a”: 1}

== Part 2 ==
Write a function minByOrder that takes a database table and a list of columns, and
returns the row with the minimum column values using the tie-breaking logic above.
If only one column is provided, then the behavior of minByOrder is identical to
passing that column to minByColumn:
minByOrder(table, [column]) is equal to minByColumn(table, column)
As in Part 1, you should use tests to demonstrate that it’s correct, either via an
existing testing system or one you create.

Examples

table2= [
{“x”: 1, “y”: 3},
{“x”: 1, “y”: 0}
]
minByOrder(table2, [“x”, “y”]) returns {“x”: 1, “y”: 0}
table3 = [
{“x”: 3, “y”: -1, “z”: 0},
{“x”: 1, “y”: 10, “z”: 1},
{“x”: 1, “y”: 10, “z”: 0}
]
minByOrder(table3, [“x”, “y”, “z”]) returns {“x”: 1, “y”: 10, “z”: 0}

请问搭建测试系统是啥?直接import junit可以吗?

junit只是一部分(我的面试官完全没要求这个, 只要能assert equals就行)。主要还得写各种helper functions,把题目里input转化为你的toyDB函数所接受的形式。再者assertEquals也需要定义expected output。 所以我在帖子里说这一点对于Java党C++党不友好,因为光是input parser就写半天。。。准备这题的时候一定要考虑一下function signature用什么,才不会浪费太多时间写测试。


面的general的engineer的职位
他们会share一个online ide 一般都是coderpad 然后用zoom开视频会议~ 我没有sharescreen 就是share 了ide
面试官是个特别nice的白人大叔,一边面试我一边在跑步,特别chill

第一个问题:

Write a function minByColumn that takes a database table (as above), along with a
column, and returns the row that contains the minimum value for the given column.
If a row doesn’t have any value for the column, it should behave as though the
value for that column was zero.
注意啊 这里没有这个key,当作有这个key 且value为0. 楼主当时脑抽了 反应了好久
这里没有这个key,当作有这个key 且value为0.
比如我找a 一个是{‘b’:0} 一个是{‘a’: 1}应该返回第一个

第二个问题:

Write a function minByOrder that takes a database table and a list of columns, and
returns the row with the minimum column values using the tie-breaking logic above.
If only one column is provided, then the behavior of minByOrder is identical to
passing that column to minByColumn:
minByOrder(table, [column]) is equal to minByColumn(table, column
要求不可以sort input list
就是给一个list of keys,让你根据这些keys排序。。。楼主当时提出用comparator,面试官很高兴,我就开始写,结果写到一半就写不下去了。。。因为一时忘记了怎么把排好的map拿出来,而且又紧张。。。
最后就是 我给了solution 但是没有时间写了 就问了下他其他问题
很伤心啊,面试官人超好的,一直保持微笑,特别nice。。。

1 Like