f*******y 发帖数: 348 | 1 45 min, use google doc and phone.
1. write a function isAngram(String s1, String s2) ==> boolean
what's the complexity? how to improve it
2. write a function dayOfWeek("01-08-2010") return "Sunday"
3. in the case of google book, there might be multiple copies for a title, if user search for this book,
how to decide which one to return?
4. in the case that there are multiple servers doing question 3, how to
synchronize the result? | s*********t 发帖数: 1663 | 2 4是啥意思?
【在 f*******y 的大作中提到】 : 45 min, use google doc and phone. : 1. write a function isAngram(String s1, String s2) ==> boolean : what's the complexity? how to improve it : 2. write a function dayOfWeek("01-08-2010") return "Sunday" : 3. in the case of google book, there might be multiple copies for a title, if user search for this book, : how to decide which one to return? : 4. in the case that there are multiple servers doing question 3, how to : synchronize the result?
| l******e 发帖数: 12192 | 3 第3问啥意思?
【在 f*******y 的大作中提到】 : 45 min, use google doc and phone. : 1. write a function isAngram(String s1, String s2) ==> boolean : what's the complexity? how to improve it : 2. write a function dayOfWeek("01-08-2010") return "Sunday" : 3. in the case of google book, there might be multiple copies for a title, if user search for this book, : how to decide which one to return? : 4. in the case that there are multiple servers doing question 3, how to : synchronize the result?
| f*******y 发帖数: 348 | 4 问题4 时候问题3 的延续。 我给问题3 的回答是用一个priority list,depends on
user's action increase the count for a book. then he asked me if there
are multiple servers, how to synchronize this list? my answer to that is I
assume these servers are accessing the same database, he said, that makes
sense :) | f*******y 发帖数: 348 | 5 sorry, 我没写全, 刚刚改了, 再看一遍吧
【在 l******e 的大作中提到】 : 第3问啥意思?
| x***y 发帖数: 633 | 6 for 3, popularity? for 4, combine all the # of searches from the servers
together?
【在 f*******y 的大作中提到】 : 45 min, use google doc and phone. : 1. write a function isAngram(String s1, String s2) ==> boolean : what's the complexity? how to improve it : 2. write a function dayOfWeek("01-08-2010") return "Sunday" : 3. in the case of google book, there might be multiple copies for a title, if user search for this book, : how to decide which one to return? : 4. in the case that there are multiple servers doing question 3, how to : synchronize the result?
| s*********t 发帖数: 1663 | 7 support
【在 x***y 的大作中提到】 : for 3, popularity? for 4, combine all the # of searches from the servers : together?
| I**A 发帖数: 2345 | 8 这个第二题,你是怎么做的?
多谢!
if user search for this book,
【在 f*******y 的大作中提到】 : 45 min, use google doc and phone. : 1. write a function isAngram(String s1, String s2) ==> boolean : what's the complexity? how to improve it : 2. write a function dayOfWeek("01-08-2010") return "Sunday" : 3. in the case of google book, there might be multiple copies for a title, if user search for this book, : how to decide which one to return? : 4. in the case that there are multiple servers doing question 3, how to : synchronize the result?
| z****n 发帖数: 1379 | 9 这题输入不可能只有那一个日期吧,因为日期是死的,星期几是人为定义的,至少先有
个起始条件说明某个日期是星期几才能做出来。
除非允许用系统函数查
【在 I**A 的大作中提到】 : 这个第二题,你是怎么做的? : 多谢! : : if user search for this book,
| I**A 发帖数: 2345 | 10 所以才问哪。。。
【在 z****n 的大作中提到】 : 这题输入不可能只有那一个日期吧,因为日期是死的,星期几是人为定义的,至少先有 : 个起始条件说明某个日期是星期几才能做出来。 : 除非允许用系统函数查
| K******g 发帖数: 1870 | 11 我的代码
/*write a function dayOfWeek("01-08-2010") return "Sunday"*/
//assuming the base date is xxxx year Jan 1st
enum weekday {Sun=0, Mon=1, Tue=2, ...}
int dayOfWeek(char* str)
{
if(str == NULL) return;
int month = atoi(str);
int day = atoi(str[3]);
int year = atoi(str[6]);
int days = (year - base_year)*365 + howManyLeapYears(year, baseyear);
days += daysStartingThisYear(month, day, year);
return (days%7+base_weekday)%7;
}
int daysStartingThisYear(int month, int d
【在 I**A 的大作中提到】 : 所以才问哪。。。
| I**A 发帖数: 2345 | 12 可能这道题就已经assume了01-01-2010是sunday了(因为01-08-2010 will return
Sunday。
【在 K******g 的大作中提到】 : 我的代码 : /*write a function dayOfWeek("01-08-2010") return "Sunday"*/ : //assuming the base date is xxxx year Jan 1st : enum weekday {Sun=0, Mon=1, Tue=2, ...} : int dayOfWeek(char* str) : { : if(str == NULL) return; : int month = atoi(str); : int day = atoi(str[3]); : int year = atoi(str[6]);
| y*********e 发帖数: 518 | 13 第一题好做,O(n)的复杂度。count sort这两个string即可。
如果2个string都是字典里面挑选出来的单词的话,可以预先处理整个字典做成一个
hashtable,那么查询isAnagram可以达到O(1)了。
第二题,这个大概是问日历这玩意是怎么实现的。给定一个基点,比如1970年1月1日,
是星期几,然后根据输入的日期间隔的日子来推算星期。
第三题是个开放题。有很多可以跟面官讨论的。比如,用户输入了一个Title,找出跟
多本书来:
究竟是同一本书的不同版本呢,还是几个一模一样Title的书?
若是搜索引擎是做模糊查询的,比如用户输入Algorithm,可能返回Introduction to
Algorithms,也有可能返回Algorithm Design。怎么样排序呢?
看系统是否保留用户的搜索历史?比如,用户输入了一个Algorithm做了查询,点击了
返回,然后又输入了CLRS作为查询关键字?
基本上需要建立起一个给搜索结果排序的打分标准。
若是一本书的不同版本,而且用户输入之中没有数字或者版本号,那么按照最新到比较
旧的排序。若是不同的书,则是参考相似度。可 | t*q 发帖数: 104 | 14 int dayOfWeek(const char* str) {
int y, m, d;
sscanf(str, "%d-%d-%d", &m, &d, &y);
int w = y + y/4 - y/100 + y/400 + d - 1;
for (int i = 1; i < m; ++i) {
if (i == 2)
w += /* 28 + */ y % 4 == 0 && (y % 100 || y % 400 ==0);
else
w += 30 + (i % 2 ^ i >= 8);
}
return w % 7;
}
【在 K******g 的大作中提到】 : 我的代码 : /*write a function dayOfWeek("01-08-2010") return "Sunday"*/ : //assuming the base date is xxxx year Jan 1st : enum weekday {Sun=0, Mon=1, Tue=2, ...} : int dayOfWeek(char* str) : { : if(str == NULL) return; : int month = atoi(str); : int day = atoi(str[3]); : int year = atoi(str[6]);
|
|