pramp mock 8
The mall management is trying to figure out what was the busiest moment in the mall in the last year. You are given data from the door detectors: each data entry includes a timestamp(secondes in Unix Epoch format), an amount of people and whether they entered or exited.
Example of a data entry: {time : 1440084737, count: 4, type : "enter"}
Find what was the busiest period in the mall on the last year. Return an array with two Epoch timestamps representing the beginning and end of that period. You man assume that the data your are given is accurate and that each second with entries or exits is recorded. Implement the most efficient solution possible and analyze its time and space complexity.
这题明显是line sweep,不过得注意相同时间有进有出时,要先减掉再加上。不然的话结果就不对了。最后这题只是返回最大时间点,我在想,如果follow up要求返回的是一段时间的开始和结束得怎么做。个人觉得可以在update max时的else里记录什么时候local max变小了。然后那个就是max period的终点,不过返回时要判断是否起点<终点,是才返回,因为有一种情况是,max一直保持到最后,那样的话最后一次变小就不存在。那时候返回[entry i, entry i]
Last updated