2021fall Bloomberg校招

9/28 一面

  1. binary tree path sum
  2. left side view of binary tree

11/10, onsite

第一轮

  1. candyCrush
    集满3+个就消掉
  2. OOD: traffic
    swipeIn(uid, time, station)
    swipeOut(uid, time, station)
    getAvg(startStation, endStation)
    我提供的思路是,两个map分别记录in & out。在getAvg里面,遍历两个map找到对应的uid。优点是能够解决如下输入。
swipeIn(0, 1, s0)
swipeIn(0, 3, s1)
swipeOut(0, 2, s0)
...

但是面试官说这样getAvg的时间复杂度太高了,而且可以假设一定按照时间顺序。(时间太紧张了,其实这道题很多地方可以讨论。我觉得在第二道题出ood是很不严谨)。
所以让我实现了另一种,在swipeIn的时候记录信息,在swipeOut的时候找到swipeIn对应uid,更新相应起点和终点总的时间和计数。getAvg直接就是从map里面拿信息一除就好。三个方法时间复杂度都是O(1)。

第二轮

  1. Can order be filled? 每个trader有不同的availability。要求order的时段在availability里面。

实际上可以用merge interval来解。

follow up: what if availabilities and order can be across 2 days?
把一个间隔拆成两个。

  1. search the grid to find a way out. 给一个grid,1代表墙,2代表出口,其他都是0,起点在(0,0)。

如果需要recover path,我采用dfs。如果只是确认能不能出去,我采用bfs。讨论了一下时间复杂度。

猜你喜欢

转载自blog.csdn.net/qq_40136685/article/details/120964245
今日推荐