由买买提看人间百态

topics

全部话题 - 话题: buffing
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
d*k
发帖数: 207
1
来自主题: JobHunting版 - 请教一个fb面试问题
//欢迎拍砖,共同提高。
char* readLine(char* ret) {
vector store;
static char buf[SIZE];
static buf_size = 0;

while (true) {
if (buf_size == 0) {
buf_size = read(buf, SIZE);
}
int last = 0;
for (last = 0; last < buf_size && buf[last] != '\n'; ++last);
copy(buf, buf + last, back_inserter(store));
if (last < buf_size) {
buf_size = buf_size - (last + 1);
memmove(buf, buf + last + 1, buf_size)
... 阅读全帖
h**o
发帖数: 548
2
来自主题: JobHunting版 - 问 Implement readline using read4096
贴个我的吧:
#define FOURK 4096
class readbuf{
readbuf(){nsize = 0; ptr = 0;}
char buf[FOURK];
int ptr;
int nsize;
int readN(char*dst, int n);
int readLine(string& s);
};
int readbuf::readN(*dst, int n){
if (!dst) return 0;
int bytes = 0;
while(n>0){
if (nsize==0) {nRead = read4K(buf); nsize = nRread; ptr = 0;}
min = min(n, nsize);
bytes+=memcpy(dst+bytes, buf, min);
ptr+=min; n-=min; nsize-=min;
if (nRead0 or ==0... 阅读全帖
g****v
发帖数: 971
3
来自主题: JobHunting版 - 请教个LC的新题
Read N Characters Given Read4 II - Call multiple times
测试的输出是:
Input: "ab", [read(0),read(1),read(2),read(1)]
Output: ["","a","b","b"]
Expected: ["","a","b",""]
我的思路很简单,就是把上次没读完的保留下来(并且是把没读完的字符移动到index
0). 下次读的时候先读上次剩下的。但不知道为什么不对?
class Solution {
int left = 0; //length of left chars of last time reading, staring from
0 of leftover.
char leftover[4];//left chars are stored here.
public:
/**
* @param buf Destination buffer
* @param n Maximum number of characters t... 阅读全帖
G********7
发帖数: 256
4
来自主题: Programming版 - 包含指针的类和vector的问题
我有一个类,里面包含一个指针,大致如下
class A
{
int a;
int* buf;
A(){a=0;buf=0}; // default constructor
A(const A& in){ // copy constructor
a=in.a;
buf=new int[a];
memcpy(buf,in.buf,sizeof(int)*a);
};

~A(){ if(buf!=0) delete[] buf;}; // destructor
};
程序里面定义了一个vector vec,然后我试图向里面insert一个object,如下
vector
vec;
vec.insert(vec.begin(),obj_A); // obj_A is an object of class A
这时候就出问题了。我debug的时候发现,vector的insert函数是先给obj_A复制一个
copy,叫做obj_A_copy,然后把obj_A_copy赋值给vec[0]。当退出insert函数时,
obj_
p******s
发帖数: 18
5
来自主题: Programming版 - 诚心请教一个linux c问题
{
char buf[64];
unsinged long long t;
snprintf(buf,64,"%llu",t);
...
}
安全吗?
还是最好写成
{
char buf[64];
memset(buf,0,64);
unsinged long long t;
snprintf(buf,64,"%llu",t);
...
}
或者
{
char buf[64];
unsinged long long t;
if(snprintf(buf,64,"%llu",t)>-1)
{
}
...
}行吗?
q******u
发帖数: 46
6
来自主题: JobHunting版 - 算法:按照字典序求第k个排列数
可以算出第一位是floor((k-1)/(n-1)!)+1,剩余的递归就好了。非递归的程序如下:
void print_comb_kth(int n, int k){
int fac = 1;
int i, j;
int *buf;
for (i=2; i<=n; i++) fac*=i;
if (k>fac || k<1){
printf("Index out of range!\n");
return;
}

if (n==1){
printf("1\n");
return;
}
buf = (int*) malloc(sizeof(int)*n);

for (i=1; i<=n; i++) buf[i-1] = i;
for (i=1; i fac /= (n+1-i);
printf("%d", buf[(k-1)/fac]);
j = (k-1)/fac;
while (j buf[j] = buf[j+1];
w****x
发帖数: 2483
7
来自主题: JobHunting版 - 昨天的F家店面
妈的, 要是15分钟我也超时了
int read4096(FILE* pf);
char buf[4096];
int nLen = 0;
void readline(char* szMem, FILE* pf)
{
assert(szMem);
bool bRet = false;
char* pWrite = szMem;
while(true);
{
int i = 0;
for (; i < nLen; i++)
if (buf[i] == 0 || buf[i] == '\n')
{
bRet = true;
break;
}
int nMove = i+1;
if (!bRet)
nMove = i;
memcpy(pWrite, bu... 阅读全帖
A*****i
发帖数: 3587
8
来自主题: JobHunting版 - 贡献一个G家面试题
完全裸考,根本没想过G家,奈何人家年年骚扰这都第三年了唉……
感觉G家每次给我出题都不难,结果每次都答不好NND
一个函数叫int Read4096(char * buf)
每次从stream里面读4Kbytes,如果stream小于4K就读到stream末尾,读出结果放在buf
里面
返回值是读了多少bytes,比如buf长度1Kbytes, 那么返回值就是1024
大于4K的stream连续调用就能自动读到底
要求是写一个int ReadBytes(char * buf, num_bytes)
作为Read4096的wrapper,可以在里面直接用Read4096,num_bytes是任意数目,返回值
也是buf的长度,buf就是结果,简单点就是能读任意长度stream的wrapper
挺简单的,结果处理边界和各种判断条件栽了,写了那么久node根本把C++的数组忘干
净了……
t*******e
发帖数: 274
9
来自主题: JobHunting版 - F面经
电面那题,网上看到一种解法,这是正解么?
我有点不明白的是假如只有200bytes, 通过read4096之后是不是应该返回200(<4096)
作为结果?
public class read_4096_bytes {
public int read4096(char[] buf) {
return 4096;
}
public int read(int n, char[] buf) {
int totalRead = 0;
for (int i = 0; i < n / 4096; ++i) {
char[] tbuf = new char[4096];
int tRead = read4096(tbuf);
totalRead += copyTo(buf, totalRead, tbuf, tRead);
if (tRead < 4096) {
return totalRead;
... 阅读全帖
s***c
发帖数: 639
10
来自主题: JobHunting版 - leetcode 的新题好像不太理解题意
试了能过你那个case
char buf4[4] = {0};
int b4left = 0;
char *pa = buf4;
int read(char *buf, int n){
if (n <= b4left){
memcpy(buf, pa, n);
b4left -= n;
pa += n;
buf += n;
return n;
}
else{
memcpy(buf, pa, b4left);
n -= b4left;
buf += b4left;
}
int npre = b4left;
b4left = 0;
pa = buf4;
char *ptr = buf;
int cnt = 0, nrd = 4;
while (cnt < n && nrd == 4){
nrd = read4(buf4);
if (cnt + nrd > n){
memcpy(ptr, buf4... 阅读全帖
b**w
发帖数: 78
11
来自主题: JobHunting版 - 讨论下lc最新的那道hard题吧
Python的,写的比较乱
class Solution(object):
def addOperators(self, num, target):
"""
:type num: str
:type target: int
:rtype: List[str]
"""
result = self.helper(num, 0, target)
return result

def helper(self, num, pos, target):
result = []
if pos>=len(num):
if target==0:
result.append("")
return result
if pos==len(num)-1:
if int(num[pos])==target:
... 阅读全帖
f****e
发帖数: 923
12
来自主题: JobHunting版 - 这个followup 如何做? 求思路
readN given read 4K II. 注意这里遇到一个follow up:optimize when N
is larger than 4K。 有个假设:
如果可以调用的API 改变成 int read4K (char[] buf, int start). 默认 buf 足够
长,
start 为上次读完之后的下一个空index. 这里read 4K 就可以直接用readN里面的buf.
第一题楼主的意思是read4k(buf, start)可以用readN的buf的意思吗?
start是读的起始位置.
解法大概是假设n是4k*i + j大小,前面i下就直接读到buf里,或者读没了直接返回。
最后一下读到cache里?下次读的时候先把cache读出来再继续
l*********e
发帖数: 152
13
来自主题: Travel版 - 说说订机票的事,憋屈啊!
早两个星期一直在查slc-buf和slc-jfk的票。因为时间极其有限,想到buf看看瀑布,
必须订到下个月20号晚上那趟12点左右的票,jfk转机,早上10点多到buf。结果想要的
这个时间一直是显示21号晚上才有。无奈之下,我就把slc-jfk的票订了,放弃去buf。
本来也想再晚点订票,但一看本来jetblue和delta都有票的,现在只剩jetblue,害怕
拖两天票价上涨了,连jetblue都没有了,所以赶紧把slc-jfk的票订了。
priceline24小时内还可以取消订票,今天凌晨1点半前我还可以取消。昨天晚上一直盯
着pl看会不会有什么变动。果然,在晚上10点的时候,查到了20号晚上12点delta飞buf
的票在ATLANTA转机!心里那个激动啊,就赶紧更改为2张票刷新页面。没了!一查,原
来是one ticket left!!!我等啊等啊,刷啊刷啊,delta网也是显示one ticket
left。我气啊,烦躁,抓狂。在绝望中,24小时过了,想改票,是不可能的了。天意不
让我去buf看瀑布。
早上,刚刚,不死心跑去check一次。我出离愤怒了!delta竟然推出
t********e
发帖数: 1169
14
【 以下文字转载自 JobHunting 讨论区 】
发信人: mitbbs59 (bEQi), 信区: JobHunting
标 题: 本版1年以内的所有 面经题目,含帖子link [为大家方便]
发信站: BBS 未名空间站 (Fri Jan 29 14:20:44 2010, 美东)
不敢保证全部涵盖,大部分的都在。
我自己找了一遍,大家一起用着都方便。
不过只是含有题目的帖子 我才包含进来了,只分享经验没贴题目的 我都没有包含
进来。
大家复习着方便。
1. 一个sorted interger Array[1...N], 已知范围 1...N+1. 已知一个数字missing。
找该数字。
把原题改为unsorted,找missing数字。 performance。
2. 复制linked list。 已知每个节点有两个pointer,一个指向后一个节点,另一个指向
其他任意一节点。 O(n)时间内,无附加内存,复制该linked list。(存储不连续)
3. 一个party N个人,如果一个人不认识任何其他人,又被任何其他人认识,此人为
celeb... 阅读全帖
t********e
发帖数: 1169
15
【 以下文字转载自 JobHunting 讨论区 】
发信人: mitbbs59 (bEQi), 信区: JobHunting
标 题: 本版1年以内的所有 面经题目,含帖子link [为大家方便]
发信站: BBS 未名空间站 (Fri Jan 29 14:20:44 2010, 美东)
不敢保证全部涵盖,大部分的都在。
我自己找了一遍,大家一起用着都方便。
不过只是含有题目的帖子 我才包含进来了,只分享经验没贴题目的 我都没有包含
进来。
大家复习着方便。
1. 一个sorted interger Array[1...N], 已知范围 1...N+1. 已知一个数字missing。
找该数字。
把原题改为unsorted,找missing数字。 performance。
2. 复制linked list。 已知每个节点有两个pointer,一个指向后一个节点,另一个指向
其他任意一节点。 O(n)时间内,无附加内存,复制该linked list。(存储不连续)
3. 一个party N个人,如果一个人不认识任何其他人,又被任何其他人认识,此人为
celeb... 阅读全帖
f****4
发帖数: 1359
16
class Mem{
public:
void* operator new(size_t n, int a);
void operator delete(void* p);
};
Mem* a = new(10) Mem;
a->~Mem();
delete a;
// operator new & delete work correctly
void* buf = malloc(sizeof(Mem)+sizeof(int));
Mem* b = new(buf) Mem; // wrong
b->~Mem();
free(buf);
我发现只要重载了operaor new之后,缺省的placement new的表达就出错了
重载 void* operator new(size_t n, void* buf);之后又好了
问题是我重载的这个void* operator new(size_t n, void* buf),是不是placement
new?有人说placement new是不能重载的(http://cyclopedia.name/post/e6b58
h*****g
发帖数: 312
17
来自主题: JobHunting版 - leetcode 这题insert interval怎么做?
感觉挺简单的,不知道我的理解是否对
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
struct Interval
{
int left;
int right;
Interval(int left,int right):left(left),right(right)
{
}
};
/////////////////
void merge_nosort(vector in,Interval * s)
{
int left=s->left;
int right=s->right;
vector out;
... 阅读全帖
h*****g
发帖数: 312
18
来自主题: JobHunting版 - leetcode 这题insert interval怎么做?
感觉挺简单的,不知道我的理解是否对
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
struct Interval
{
int left;
int right;
Interval(int left,int right):left(left),right(right)
{
}
};
/////////////////
void merge_nosort(vector in,Interval * s)
{
int left=s->left;
int right=s->right;
vector out;
... 阅读全帖
h*****g
发帖数: 312
19
来自主题: JobHunting版 - leetcode 这题insert interval怎么做?
感觉挺简单的,不知道我的理解是否对
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
struct Interval
{
int left;
int right;
Interval(int left,int right):left(left),right(right)
{
}
};
/////////////////
void merge_nosort(vector in,Interval * s)
{
int left=s->left;
int right=s->right;
vector out;
... 阅读全帖
h*****g
发帖数: 312
20
来自主题: JobHunting版 - leetcode 这题insert interval怎么做?
感觉挺简单的,不知道我的理解是否对
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
struct Interval
{
int left;
int right;
Interval(int left,int right):left(left),right(right)
{
}
};
/////////////////
void merge_nosort(vector in,Interval * s)
{
int left=s->left;
int right=s->right;
vector out;
... 阅读全帖
s********u
发帖数: 1109
21
来自主题: JobHunting版 - ebay skype interview面经(4轮)
挖个坟,这个readline的题目,搜了一下,好像应该是这个意思吧:
用一个buffer来存字符流,如果中间有换行,那么将这一行返回成一个字符串输出,但
是这个buffer里面的东西继续保留,下次readline()再输出;
如果一行非常长,那么可能需要用到几次read(),来拼出这个完整的line。
/*Implement a function char* readLine(); which returns single lines from a
buffer.
To read the buffer, you can makes use of a function int read(char* buf, int
len) which fills buf with upto len chars and returns the actual number of
chars filled in. Function readLine can be called as many times as desired.
If there is no valid data or newline ter... 阅读全帖
f**********t
发帖数: 1001
22
Well, my code is complex and sigfault. Let me go back if I have time.
This is too hard for a 45 minutes interview.
void skipSpace(const char **s) {
while (isspace(**s)) {
++(*s);
}
}
int getNum(const char **s) {
bool neg = false;
if (**s == '-') {
neg = true;
++(*s);
}
int cur = 0;
while (isdigit(**s)) {
cur = cur * 10 + (**s - '0');
++(*s);
}
--(*s);
return neg ? -cur : cur;
}
int opNum(int x, int y, char op) {
switch (op) {
case '+':
return x + y... 阅读全帖
b**l
发帖数: 33123
23
来自主题: Football版 - 2013 MITBBS NFL Sucker Survivor Game
Sucker Survivor List (4 as of 11/5) plus Week 1-9 Results
以报名先后为序
TaiNiuLe GB CLE JAC PHI DET ARI TB BUF MIN
whatwhenever BUF NYJ OAK PHI JAC TEN HOU WSH TB
apolitical BUF NYJ OAK JAC DAL TEN HOU WSH MIN
Heap BUF STL OAK PHI DAL ARI CLE WSH TB
Eliminated
Week 9: {devince,JackJones}(CHI), greatwall123(NYJ), infocat(absence)
Week 7: {zli,wxx07,PPXIA}(IND), {bbdou,Manuel}(BUF)
Week 6: NittanyLion(STL)
Week 5: Nazi(DEN), {pplulu,HM2013,Dalang,Tomato9,pumpkin18,fotoid,
octoberlunar,newtiger,FTSCI,dom... 阅读全帖
a9
发帖数: 21638
24
我说说我的吧:
80口开的apache,允许connect到443
openvpn开443,侦听127.0.0.1
服务器端:
mode server
tls-server
ifconfig 172.19.0.1 255.255.0.0
ifconfig-pool 172.19.0.100 172.19.254.254 255.255.0.0
proto tcp-server
port 443
local 127.0.0.1
dev tap
comp-lzo
keepalive 15 60
verb 3
ca /etc/openvpn/ca.crt
dh /etc/openvpn/dh.pem
cert /etc/openvpn/tmobilewall.crt
key /etc/openvpn/tmobilewall.key
status-version 2
status status
tmp-dir /dev/shm
auth-user-pass-verify /etc/openvpn/tmobilewall_auth.php via-file
username-as-common-... 阅读全帖
B********s
发帖数: 3610
25
来自主题: Programming版 - 关于buffer overflow
在server上有这样一个函数:
void getinput() {
int count;
char buf[12];
...
gets(buf);
...
}
gets()读入一段input到buf中。如果buf够大,可以放一段shellcode到stack上,实现
buffer overflow的攻击。问题是现在buf只有12 bytes,放不下一段shellcode,那么这
种情况下有什么办法实现攻击呢?
xt
发帖数: 17532
26
来自主题: Programming版 - Linux GNU C, readlink问题
//exec_path = new char[SSIZE_MAX];
exec_path = new char[MAX_DIR_LEN];
char buf[40]= { 0 };
ssize_t length;
pid_t pid = getpid();
sprintf(buf, "/proc/%d/exe", pid);
length = readlink(buf, exec_path, 2048);
buf[length] = 0;
if (length < 0) {
printf("Unable to read link '%s':\n", buf);
printf("errno: %d\n", errno);
return NULL;
}
exec_path[ length ]=0;
printf( "exe
l**********n
发帖数: 8443
27
来自主题: Programming版 - Scala question
读scala代码简直是摧残啊。
比如这个:
/**
* Sort so that subtypes always precede their supertypes, but without
* obeying any order between unrelated subtypes (insert sort).
*/
private def sort(in: Iterable[ClassSerializer]): immutable.Seq[
ClassSerializer] =
((new ArrayBuffer[ClassSerializer](in.size) /: in) {
(buf, ca) ⇒
buf.indexWhere(_._1 isAssignableFrom ca._1) match {
case -1 ⇒ buf append ca
case x ⇒ buf insert(x, ca)
}
bu... 阅读全帖
n******s
发帖数: 7
28
来自主题: Computation版 - fortran求助!

character(len=80)::buf
character(len=8)::fmtstr="(??f4.2)"
integer::n,i
integer::datafile
open(unit=datafile,file="...",...)
read(unit=datafile,fmt="(a80)")buf ! read entire record into buf
n=len_trim(buf)/4 ! how many numbers? (4 chars per number)
write(unit=fmtstr(2:3),fmt='(i2)')n ! dynamically change format
read(unit=buf,fmt=fmtstr)(x(i),i=1,n,1) ! internal file read, like sscanf()
close(unit=datafile)
Also take a look at the : edit descriptor in a good Fortran book.
If you read 1234 using
r*******e
发帖数: 7583
29
来自主题: JobHunting版 - 收到G家拒信,发面经
大半夜收到HR的thank you note。不用管什么NDA了
本人ECE fresh PhD,背景是电路/EDA,跟G业务基本没什么关系
同学内部推荐的,很简单的一次电面就给了onsite
题都不难,但是自己没把握好机会,出了一些小bug。
总的感觉,出错就是硬伤,宁可从最简单的算法写起,也不能出错。
电面:
1,Skip list, http://en.wikipedia.org/wiki/Skip_list
写code实现struct skip_list * find(struct skip_list *head, int value)
2,sorted array with repeated elements
for given element, find out its range.
e.g. A A B B B B B C C D D E F G, given B, the output should be [2, 6]
binary search的变种
3,number of unique url accesses in huge log files
hashtable... 阅读全帖
f*****w
发帖数: 2602
30
来自主题: JobHunting版 - 收到G家拒信,发面经

5,文件读写
有个封装好的函数 int block_reader(char *buf)
内部有个静态文件指针,只能向文件末尾移动,不能rewind
每次只能读取4K的block到buf里,返回读取的字节数(除非到文件尾,否则总是4K)
要求实现 int anysize_reader(char *buf, int size)
从文件的当前位置读取任意大小的数据存入buf,并返回实际读到的数据字节数
白板写code
问题的关键在于anysize_reader会被多次调用,每次都可能不是4K对齐
所以需要自己维护一个4K的buffer
请教一下 我没很明白为什么要维护一个4K的buffer?
r*******e
发帖数: 7583
31
来自主题: JobHunting版 - 收到G家拒信,发面经
大半夜收到HR的thank you note。不用管什么NDA了
本人ECE fresh PhD,背景是电路/EDA,跟G业务基本没什么关系
同学内部推荐的,很简单的一次电面就给了onsite
题都不难,但是自己没把握好机会,出了一些小bug。
总的感觉,出错就是硬伤,宁可从最简单的算法写起,也不能出错。
电面:
1,Skip list, http://en.wikipedia.org/wiki/Skip_list
写code实现struct skip_list * find(struct skip_list *head, int value)
2,sorted array with repeated elements
for given element, find out its range.
e.g. A A B B B B B C C D D E F G, given B, the output should be [2, 6]
binary search的变种
3,number of unique url accesses in huge log files
hashtable... 阅读全帖
f*****w
发帖数: 2602
32
来自主题: JobHunting版 - 收到G家拒信,发面经

5,文件读写
有个封装好的函数 int block_reader(char *buf)
内部有个静态文件指针,只能向文件末尾移动,不能rewind
每次只能读取4K的block到buf里,返回读取的字节数(除非到文件尾,否则总是4K)
要求实现 int anysize_reader(char *buf, int size)
从文件的当前位置读取任意大小的数据存入buf,并返回实际读到的数据字节数
白板写code
问题的关键在于anysize_reader会被多次调用,每次都可能不是4K对齐
所以需要自己维护一个4K的buffer
请教一下 我没很明白为什么要维护一个4K的buffer?
g**u
发帖数: 583
33
马上就要G on site了,
求祝福。
下面是从本版收集到的Google的试题,便于大家查询。
申明:有的附带有解释说明的,也来自于本版或者网络,大家自己看, 不保证真确
http://www.mitbbs.com/article_t1/JobHunting/31847453_0_1.html
本人ECE fresh PhD,背景是电路/EDA,跟G业务基本没什么关系
同学内部推荐的,很简单的一次电面就给了onsite
题都不难,但是自己没把握好机会,出了一些小bug。
总的感觉,出错就是硬伤,宁可从最简单的算法写起,也不能出错。
电面:
1,Skip list, http://en.wikipedia.org/wiki/Skip_list
写code实现struct skip_list * find(struct skip_list *head, int value)
2,sorted array with repeated elements
for given element, find out its range.
e.g. A A B B B B B C C D D E F ... 阅读全帖
P**********c
发帖数: 3417
34
来自主题: JobHunting版 - 考古G面经里两道题
5,文件读写
有个封装好的函数 int block_reader(char *buf)
内部有个静态文件指针,只能向文件末尾移动,不能rewind
每次只能读取4K的block到buf里,返回读取的字节数(除非到文件尾,否则总是4K)
要求实现 int anysize_reader(char *buf, int size)
从文件的当前位置读取任意大小的数据存入buf,并返回实际读到的数据字节数
白板写code
问题的关键在于anysize_reader会被多次调用,每次都可能不是4K对齐
所以需要自己维护一个4K的buffer
6,系统设计
讨论gmail的user authentication,描述详细的流程,性能瓶颈
如何做load balancing
第5题没有看懂。
第6题有没有人大致说说。
S**I
发帖数: 15689
35
☆─────────────────────────────────────☆
gzou (gzou) 于 (Thu May 12 02:26:35 2011, 美东) 提到:
马上就要G on site了,
求祝福。
下面是从本版收集到的Google的试题,便于大家查询。
申明:有的附带有解释说明的,也来自于本版或者网络,大家自己看, 不保证真确
http://www.mitbbs.com/article_t1/JobHunting/31847453_0_1.html
本人ECE fresh PhD,背景是电路/EDA,跟G业务基本没什么关系
同学内部推荐的,很简单的一次电面就给了onsite
题都不难,但是自己没把握好机会,出了一些小bug。
总的感觉,出错就是硬伤,宁可从最简单的算法写起,也不能出错。
电面:
1,Skip list, http://en.wikipedia.org/wiki/Skip_list
写code实现struct skip_list * find(struct skip_list *head, int value)
2,sorted array... 阅读全帖
S**I
发帖数: 15689
36
☆─────────────────────────────────────☆
gzou (gzou) 于 (Thu May 12 02:26:35 2011, 美东) 提到:
马上就要G on site了,
求祝福。
下面是从本版收集到的Google的试题,便于大家查询。
申明:有的附带有解释说明的,也来自于本版或者网络,大家自己看, 不保证真确
http://www.mitbbs.com/article_t1/JobHunting/31847453_0_1.html
本人ECE fresh PhD,背景是电路/EDA,跟G业务基本没什么关系
同学内部推荐的,很简单的一次电面就给了onsite
题都不难,但是自己没把握好机会,出了一些小bug。
总的感觉,出错就是硬伤,宁可从最简单的算法写起,也不能出错。
电面:
1,Skip list, http://en.wikipedia.org/wiki/Skip_list
写code实现struct skip_list * find(struct skip_list *head, int value)
2,sorted array... 阅读全帖
d**********x
发帖数: 4083
37
实际上是O(logn)的空间,但是既然长度为2^32的数列可以借助一个int来作为辅助空间
,这点overhead基本可以忽略不计了。欢迎找bug:
#include
#include
#include
using namespace std;
#include
static int get_index(int i) {
if (i == 0) {
return 1;
}
return (1 << i) + 1;
}
void rearrange(vector& vec) {
int bitmap = 0; //"O(1)" space for length < (1 << 32)
int k = vec.size() / 2;
int n = vec.size();
for (int i = 0; get_index(i) < k; ++i) {
int cur = get_index(i);
... 阅读全帖
d*k
发帖数: 207
38
這種需求第一次寫的時候如果沒說,之後他指出,你再加上也算可以吧?要是要求一次
就寫出來有點成心黑你啊。
改一下我的,我覺得還比較好改啊。
int Read(int size, char* buffer) {
static char extra[4];
static extra_len = 0;
int ret = 0;
if (extra_len > 0) {
int t = min(extra_len, size);
memcpy(buffer, extra, t);
ret += t;
extra_len -= t;
size -= t;
}
int n = size / 4;

for (int i = 0; i < n; ++i) {
int t = Read4(buffer + ret);
ret += t;
if (t < 4) {
return ret;
... 阅读全帖
c***d
发帖数: 26
39
来自主题: JobHunting版 - read4 / read4k 实现readAny复杂吗?
前几天看这里讨论说用read4/read4k实现readAny边界条件比较多容易出错, 今天写了
一下,发现没什么边界条件啊。大牛看看哪里可能出问题。
用javascript写的,不过基本语法和c/java没啥区别。就这两行可能比较拗口:
var args = [bytes, 0].concat(store.splice(0, numToCopy));
[].splice.apply(buf, args);
它做的无非就是从store数组里刨去前numToCopy个元素,再把他们append到buf数组。
readAny函数在这里。完整的带unit test和mock read4()的code在 https://gist.
github.com/dumpty/7176257。可以用node执行,或者直接考到chrome dev console里
运行。
var readAny = (function() {
var store = [];
return function(n, buf) {
... 阅读全帖
h**o
发帖数: 548
40
来自主题: JobHunting版 - 讨论一下FB的经典题read和readline吧
int readbuf::readLine(string& s){
int bytes = 0; bool endline = false;
while(1){
if (nsize==0) {nRead = read4K(buf); nsize = nRread; ptr = 0;}
for(; ptr< FOURK && nsize>0;ptr++, nsize--) {
s.append (buf[ptr]); bytes++;
if (buf[ptr] == ' 0 ' || buf[ptr] ==' n') endline=true;
}
if (endline || nRead }
}
a****r
发帖数: 87
41
来自主题: JobHunting版 - MapR周五onsite,求bless
上周四和他家面试了。里面全是印度人。其实个人对印度人没有意见。engineer 和
manager are okay. But the VP of engineering is joke. He was disrespectful. I
walked out after the interview:( Very bad experience for me.
Wish you the best luck! 他家的问题会问多线程和系统设计。Hope it helps.
Bounded Buffer supporting multithreading.
class Buffer{
private:
vector buf;
int start, end;
int size;
int capacity;

mutex mt;
condition_variable dt_cv;
condition_variable sp_cv;

public:
Buffer(int N): buf(N){
st... 阅读全帖
c**1
发帖数: 71
42
来自主题: JobHunting版 - 问一道Facebook近期电面题
$ cat x.cc; g++ x.cc; ./a.out
#include
void f(char* str) {
int left = 0;
char* p;
for (p = str; *p; ++p) {
if (*p == '(') {
++left;
} else if (left != 0) {
--left;
} else {
*p = ' ';
}
}
for (--p; p >= str && left != 0; --p) {
if (*p == '(') {
*p = ' ';
--left;
}
}
}
int main() {
char buf[] = ")()))))))(()()(())())()))))))))";
printf("%s\n", buf);
f(buf);
printf("%s\n", buf);
return 0;
}
)()))))))(()()(())())()... 阅读全帖
A*******e
发帖数: 2419
43
来自主题: JobHunting版 - LC的简单版Read4是这样吗?
不停从source读,向target写。直到source里剩下不到4个,或者target里剩下不到4个
为止。然后判断是没读的少,还是没写的少,取最小值再读写一下。
class Solution {
public:
int read(char* buf, int n) {
int total_bytes = 0;
int bytes = 0;
char tmp[4];
while ((bytes = read4(tmp) == 4 && total_bytes <= n - 4) {
memcpy(buf, tmp, bytes);
total_bytes += bytes;
buf += bytes;
}
int remain_bytes = min(bytes, n - total_bytes);
memcpy(buf, tmp, remain_bytes);
return t... 阅读全帖

发帖数: 1
44
来自主题: JobHunting版 - read4 vs read4II 到底啥区别?
读4
这道题给了我们一个Read4函数,每次可以从一个文件中最多读出4个字符,如果文件中
的字符不足4个字符时,返回准确的当前剩余的字符数。现在让我们实现一个最多能读
取n个字符的函数
int read(char *buf, int n) {
int res = 0;
for (int i = 0; i <= n / 4; ++i) {
int cur = read4(buf + res);
if (cur == 0) break;
res += cur;
}
return min(res, n);
}
读4 II Read N Characters Given Read4的拓展,那道题说read函数只能调用一次,而
这道题说read函数可以调用多次
int read(char *buf, int n) {
for (int i = 0; i < n; ++i) {
if (readPos == writ... 阅读全帖
t******g
发帖数: 10390
45
来自主题: Football版 - 号称拿过sb的51个球队里
Rk Loser win% Year Winner win%
1 ATL 1/1 2016 NWE 1/1
2 CAR 1/1 2015 DEN 1/1
3 SEA 2/2 2014 NWE 1/1
4 DEN 1/2 2013 SEA 1/1
5 SFO 1/1 2012 BAL 1/1
6 NWE 2011 NYG
7 PIT 1/1 2010 GNB
8 IND 1/1 2009 NOR
9 ARI 0/1 2008 PIT 1/1
10 NWE 2007 NYG
11 CHI 2006 ... 阅读全帖
k*****r
发帖数: 21039
46
for eg, I have a C function that grab video frame buf from
camera for me, whenver a buffer is ready, the function
returns data. I hope in Matlab, I can access these info.
char buf[MAX_BUF];
int getVideoBuf(buf, x, y, w, h)
{
memcpy(buf, VBUF, w*h*sizeof(char));
}
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)