# 近期Stripe面经总结

不过感觉以前的资料写的不太全，自己再稍稍整理一下，算是回报吧。

https://gist.github.com/weiqitoby600/fd3db87ae8123432c844fb1601413525

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

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

algorithm那 轮的题目是

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

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

例如不使用反面，那就是一共扣 0+0+1+0+1+0=2分。

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

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

2 Likes

OA和店面总结一下是5题

3月24日条带Stripe的OA

Rader Rule, 改动的地方是只有 == 和 != 但是 rule里空格是optional的，就是可以出现"amount==100" 或者 “amount ==100”, 如果用split() 比如我，就要小心这个，要先用replace把"==" 都换成" == " 然后再split。
13个 样例过了12个，满打满算用完了75分钟。我没有特殊处理过corner case。可能是中间处理方式不同造成的吧。

1. platform balance
2019 Intern OA

“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”

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

GHC Job Fair - new grad

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"
``````

Q1: String allocate（String serverType) 参考leetcode41
Q2: deallocate(String ServerName) 这个serverName 里包含数字，需要用regex解析出来。

1. score

O(n) 解法可以是从左扫一遍得到 leftPresum, 然后从右扫一遍得到 rightPresum, 从右扫的时候翻转一下。

1. rate limiter

Onsite

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?

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

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}

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

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.

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

1 Like