有人吃melatonin吗?好不好# PennySaver - 省钱一族
i*h
1 楼
想避开system design所以投了SET, 电面聊了一堆怎么测试,最后剩20分钟老印说只有
一题,题目如下,面试的时候让我自己写个Pair class,然后开始做题要求返回 List<
Node>,我写了一半就超时了。哪个大牛给解一下吧,我没想明白怎么做。
Write a function that receives a set of node dependencies and return a list
of nodes such that the independent nodes are generated first.
- For example, Input= { (A, B), (B, C) (D, C) } where a pair (A, B)
indicates that node A depends on node B. Output= [C, B, D, A]
- Another example, Input = { (A B) (B C) (E A) (Q B) (Q C)} could generate [
C B A Q E].
- Small example. I = { (A B) (B C) } O = [C B A]
一题,题目如下,面试的时候让我自己写个Pair class,然后开始做题要求返回 List<
Node>,我写了一半就超时了。哪个大牛给解一下吧,我没想明白怎么做。
Write a function that receives a set of node dependencies and return a list
of nodes such that the independent nodes are generated first.
- For example, Input= { (A, B), (B, C) (D, C) } where a pair (A, B)
indicates that node A depends on node B. Output= [C, B, D, A]
- Another example, Input = { (A B) (B C) (E A) (Q B) (Q C)} could generate [
C B A Q E].
- Small example. I = { (A B) (B C) } O = [C B A]