新人帖,大家請見諒:
小弟今天早上剛結束狗家的電面,上來分享一下今天面的題目,希望能幫助到最近要面谷歌的大佬們
1.
Given an array “log” with N entries (N in the order of billions) and M type of numbers in the array. Define a function isMoreThanHalf(startIdx, endIdx, logType). Determine if the “logType” appears more than half of the subarray starts from “startIdx” and ends in “endIdx”.
For example,
log = [6, 6, 6, 7, 3, 8]
isMoreThanHalf(0, 3, 6) -> True
isMoreThanHalf(1, 4, 6) -> False
isMoreThanHalf(2, 5, 7) -> False
Note: startIdx and the endIdx is the closed interval.
startIdx could be the same as endIdx.
You are now able to use a preprocess function one time. How would you define the function?
def preprocess():
How would you utilize your preprocess function to improve 1. ?