一道面试题求解# JobHunting - 待字闺中
d*3
1 楼
让我写一个calculate the nth number in fibonacci sequence的函数:
我给出了一个非递归版本,
public static int fibnacci_M(int i) {
if (i<=2) {
return 1;
} else {
int[] value = {1,1};
int sum = 0;
while (i>2) {
sum = value[0] + value[1];
value[1] = value[0];
value[0] = sum;
i--;
}
return sum;
}
}
然后他问我如果用递归复杂度多少。之后为我这个函数能不能马上deploy到Server上,
然后can this function be used to calculate the 1 billion th number, how to
improve the function to calculate large number. Will you calculate the
result for each request, if using cache how do you store and retrieve the
cache, will you store the cache in each app server? How many servers and how
much space do you need to store and calculate the cache.
我说了用java的BigInteger,然后扯了一些distributed system的东西,不过因为没做
过就随便说了说,面试官没满意,想问问版上各位这些问题该怎么答呢。
我给出了一个非递归版本,
public static int fibnacci_M(int i) {
if (i<=2) {
return 1;
} else {
int[] value = {1,1};
int sum = 0;
while (i>2) {
sum = value[0] + value[1];
value[1] = value[0];
value[0] = sum;
i--;
}
return sum;
}
}
然后他问我如果用递归复杂度多少。之后为我这个函数能不能马上deploy到Server上,
然后can this function be used to calculate the 1 billion th number, how to
improve the function to calculate large number. Will you calculate the
result for each request, if using cache how do you store and retrieve the
cache, will you store the cache in each app server? How many servers and how
much space do you need to store and calculate the cache.
我说了用java的BigInteger,然后扯了一些distributed system的东西,不过因为没做
过就随便说了说,面试官没满意,想问问版上各位这些问题该怎么答呢。