Thursday, February 19, 2009

ms sdet 面经

发信人: redcrab (RedCrab), 信区: JobHunting
标 题: 报告一个offer: ms sdet
发信站: BBS 未名空间站 (Wed Feb 18 14:40:19 2009)


一月份的面试,中间HR拖延了很久,昨天收到offer letter

给大家鼓气,虽然形式不好,不断尝试,总会有offer的

背景:fresh phd, 排名40左右的学校,没有工作经验

Offer: 80k base salary, no sign on bonus, NOT negotiable
   感觉给得很低,我尝试negotiate, 没有成功。

面经:

一共面了五个人,问的题目不难。

1。对着简历一条一条问,然后问如何实现strcpy,
  strcpy有什么缺点,如何测试。

2。给一个单向链表,每一个结点存一个整数,如何删除链表中的素数。
  我在白板上写了程序,他又问如何测试。

3。Lunch interview, 问了“If you find that you have been behind the schedule
and cannot catch up the deadline, what shall you do?", "What's your
interest (in testing)?"。

4。How to design a routine algorithm for GPS? What's the data structure? How
shall you test it?

5. A manager, 主要问了behavior question. "What's your strength?" "What's
your weakness?". "How to test the scheduling controller of an elevator".


面试前看了一个网站,http://placementsindia.blogspot.com/
感觉总结得不错,希望对大家有帮助。

Saturday, January 24, 2009

review

If you are CS, make sure to review all C/C++ basics,

for C, there is always questions on pointers and I like the tutorial:
http://www.cs.cf.ac.uk/Dave/C/CE.html


for C++, they tend to ask things about polymorphism, virtual members,
abstract class, there is a tutorial talking about the basics with examples:
http://www.cplusplus.com/doc/tutorial/

Tuesday, November 18, 2008

amazon on-stie interview questions(zz)

发信人: chuncl (ray), 信区: JobHunting
标 题: amazon on-stie interview questions
发信站: BBS 未名空间站 (Tue Nov 18 15:21:21 2008)

Today, I got the call that I am failed. pretty sad. I got a lot from this
board, hope these interview questions would be helpful for others, and wish
everyone get good luck.

1st person
Given n numbers, there is one appeared more than n/2 times, find it, coding
Reverse double link list, coding
design data structure that support do/undo

2nd
Serialize a Binary tree (Not BST) into array.
I mentioned
a) Something like heap, but space expensive for un-balanced tree
b) pre-order + in-order
c) level by level

Then, the interviewer ask to just use preorder to do it, Using 0 to denote
the NULL. I wrote code using markers.
Then he asked what happened if we are not allowed using any other markers,
then some discussion.

3rd
Research related questions regarding machine learning, text mining, and pattern
recognition. Lunch

4th
Find longest repetitive substrings in a string.
I gave suffix array approach and wrote the code, but the interviewer thought
brutal approach is better ( I tried to communicate with him, but it seems
not go well and he seems a little bit upset)
Then ask me the mechanism of java garbage collection, how to implement/
simulate it in c++
How to design quick search data structure when you input an address, then
output the longitude/latitude.
Some c++ questions

5th
Design a excel worksheet, that support literal, e.g., “500”, also
expressions, e.g., A4=“A1+A5”, A4=f(A1,A2,A6)..etc

6th
Design desktop gui. On gui, there is “program”, “folder”, “printer”,
“garbage can”, “file”, we can drag each one to another one. But some are
legal, some are not. E.g., when we drag file into printer, it is legal, and
printer will print file out. When we drag a folder into printer, it is also
legal, printer will print out all the files in the folder(could be
recursive). But some operations are illegal, e.g., when we drag "garbage can
" to printer, there should error message or exception sent out.
Hint: don’t use static binding e.g., ID, but use dynamic binding and
polymorphisms.

微软面经(zz)

发信人: sheart (test), 信区: JobHunting
标 题: 微软面经
发信站: BBS 未名空间站 (Fri Nov 14 21:09:51 2008)

刚面完,发面经攒rp

1. lead: find the most frequent word(s) in a Word doc. What are the things
you need to clarify before coding?

用hashtable,注意多个单词有相同最高频率的情况

2. dev: 1) clone a linked list (get an exactly same copy of the original
list)
2) clone a linked list with pointers not only to the next node, but
also to the node after the next
3) clone a linked list with two pointers, one to the next node, the
other to a random node in the list or null

对每个节点都新建一个相应的节点,再连起来
random指针那问,可以建一个表,存新老节点的对应关系

3. dev: find if a loop exists in a linked list
reverse words in a sentence

4. lead: in-order traversal of a binary tree without using recursion
string permutation
how to do text summarization (open question)

text summarization,我就说给不同的句子赋不同的权重,开头结尾、标题等的权重高
这个没有固定答案的,就和平时聊天扯research一样

5. vp: given a document and a query (of several keywords), find the minimum
span that contains all the keywords in the query

这题大家讨论的挺充分了。我当时给的就是一个很直观的解法,没考虑优化,写完code之后又说了说应该怎么优化,就过了。所以感觉先给出一个working solution最重要。

基本就是这样了,祝大家都找工顺利~~

-----------------------------------------------------------------------------------
题目都不算难,感觉面试的人其实也都没好好准备,随便想道题就问了
教训就是,遇到看过的题别太高兴-___-|| 很快答出来,他们会换道题接着问的...

Tuesday, November 4, 2008

epoll同时处理海量连接的代码

#include < stdio.h >
#include < stdlib.h >
#include < errno.h >
#include < string.h >
#include < sys/types.h >
#include < netinet/in.h >
#include < sys/socket.h >
#include < sys/wait.h >
#include < unistd.h >
#include < arpa/inet.h >
#include < openssl/ssl.h >
#include < openssl/err.h >
#include < fcntl.h >
#include < sys/epoll.h >
#include < sys/time.h >
#include < sys/resource.h >


#define MAXBUF 1024
#define MAXEPOLLSIZE 10000

/*
setnonblocking - 设置句柄为非阻塞方式
*/
int setnonblocking(int sockfd)
{
if (fcntl(sockfd, F_SETFL, fcntl(sockfd, F_GETFD, 0)|O_NONBLOCK) == -1) {
return -1;
}
return 0;
}

/*
handle_message - 处理每个 socket 上的消息收发
*/
int handle_message(int new_fd)
{
char buf[MAXBUF + 1];
int len;
/* 开始处理每个新连接上的数据收发 */
bzero(buf, MAXBUF + 1);
/* 接收客户端的消息 */
len = recv(new_fd, buf, MAXBUF, 0);
if (len > 0)
printf
("%d接收消息成功:'%s',共%d个字节的数据\n",
new_fd, buf, len);
else {
if (len < 0)
printf
("消息接收失败!错误代码是%d,错误信息是'%s'\n",
errno, strerror(errno));
close(new_fd);
return -1;
}
/* 处理每个新连接上的数据收发结束 */
return len;
}
/************关于本文档********************************************
*filename: epoll-server.c
*purpose: 演示epoll处理海量socket连接的方法
*wrote by: zhoulifa(zhoulifa@163.com) 周立发(http://zhoulifa.bokee.com)
Linux爱好者 Linux知识传播者 SOHO族 开发者 最擅长C语言
*date time:2007-01-31 21:00
*Note: 任何人可以任意复制代码并运用这些文档,当然包括你的商业用途
* 但请遵循GPL
*Thanks to:Google
*Hope:希望越来越多的人贡献自己的力量,为科学技术发展出力
* 科技站在巨人的肩膀上进步更快!感谢有开源前辈的贡献!
*********************************************************************/
int main(int argc, char **argv)
{
int listener, new_fd, kdpfd, nfds, n, ret, curfds;
socklen_t len;
struct sockaddr_in my_addr, their_addr;
unsigned int myport, lisnum;
struct epoll_event ev;
struct epoll_event events[MAXEPOLLSIZE];
struct rlimit rt;

if (argv[1])
myport = atoi(argv[1]);
else
myport = 7838;

if (argv[2])
lisnum = atoi(argv[2]);
else
lisnum = 2;

/* 设置每个进程允许打开的最大文件数 */
rt.rlim_max = rt.rlim_cur = MAXEPOLLSIZE;
if (setrlimit(RLIMIT_NOFILE, &rt) == -1) {
perror("setrlimit");
exit(1);
}
else printf("设置系统资源参数成功!\n");

/* 开启 socket 监听 */
if ((listener = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
perror("socket");
exit(1);
} else
printf("socket 创建成功!\n");

setnonblocking(listener);

bzero(&my_addr, sizeof(my_addr));
my_addr.sin_family = PF_INET;
my_addr.sin_port = htons(myport);
if (argv[3])
my_addr.sin_addr.s_addr = inet_addr(argv[3]);
else
my_addr.sin_addr.s_addr = INADDR_ANY;

if (bind
(listener, (struct sockaddr *) &my_addr, sizeof(struct sockaddr))
== -1) {
perror("bind");
exit(1);
} else
printf("IP 地址和端口绑定成功\n");

if (listen(listener, lisnum) == -1) {
perror("listen");
exit(1);
} else
printf("开启服务成功!\n");

/* 创建 epoll 句柄,把监听 socket 加入到 epoll 集合里 */
kdpfd = epoll_create(MAXEPOLLSIZE);
len = sizeof(struct sockaddr_in);
ev.events = EPOLLIN | EPOLLET;
ev.data.fd = listener;
if (epoll_ctl(kdpfd, EPOLL_CTL_ADD, listener, &ev) < 0) {
fprintf(stderr, "epoll set insertion error: fd=%d\n", listener);
return -1;
} else
printf("监听 socket 加入 epoll 成功!\n");
curfds = 1;
while (1) {
/* 等待有事件发生 */
nfds = epoll_wait(kdpfd, events, curfds, -1);
if (nfds == -1) {
perror("epoll_wait");
break;
}
/* 处理所有事件 */
for (n = 0; n < nfds; ++n) {
if (events[n].data.fd == listener) {
new_fd = accept(listener, (struct sockaddr *) &their_addr,
&len);
if (new_fd < 0) {
perror("accept");
continue;
} else
printf("有连接来自于: %d:%d, 分配的 socket 为:%d\n", inet_ntoa(their_addr.sin_addr), ntohs(their_addr.sin_port), new_fd);

setnonblocking(new_fd);
ev.events = EPOLLIN | EPOLLET;
ev.data.fd = new_fd;
if (epoll_ctl(kdpfd, EPOLL_CTL_ADD, new_fd, &ev) < 0) {
fprintf(stderr, "把 socket '%d' 加入 epoll 失败!%s\n",
new_fd, strerror(errno));
return -1;
}
curfds++;
} else {
ret = handle_message(events[n].data.fd);
if (ret < 1 && errno != 11) {
epoll_ctl(kdpfd, EPOLL_CTL_DEL, events[n].data.fd,
&ev);
curfds--;
}
}
}
}
close(listener);
return 0;
}

一些面试的问题(计算机类)

什么是Deadlock?如何避免?
什么是virtual method?
Interface和abstract class的区别?
Linkedlist, Array, Hashtable各有什么优点和缺点?
Thread和Process各是什么?有什么区别?
什么是Static Class?

写Reverse Word的Code,如何测试?
两个array,将在第二个array中出现过的element从第一个array中去掉。写code。
写Code,将Binary Tree的所有Node的value打印出来,从上到下,从左到右。如何测试
?