转发: google 2019 summer intern oa

刚刚做完Google的oa,题目没有变,还是ancestor和stores&houses两道题。地里有原题可以看一下。

ancestor是说有一个tree,用array代替,tree的node的value是 0到N-1 的,and their parents are represented in an array A, and A[i] is the number of parents if i-th node. 从这个node到root中间的所有node都是ancestor,让返回一个array,to find the ancestor at distance D of every node of the tree. distance就是对应的shortest path。其中A[0]=-1因为0是root节点。如果没有ancestor了也返回-1

stores&house 就是两个数组,一个代表stores,一个代表houses的location,for each house, find the store closest to it, 如果有相等,返回numerical小一点的值。