Nividia phone interview

原帖地址:一亩三分地

1, Count maximum O around X

in = “OOOXOOOOXOXOOOOXOXXOOOO”

out = 7

int CountSuroundO(string s)
{
int n = s.size();
if(n==0) return 0;

int start = 0;
int pos = s.find(‘X’, start);
if(pos == string::npos) return 0;

int prelen = pos-start;
start = pos+1;
int maxlen = 0;
while(1)
{

int pos = s.find(‘X’, start);
if(pos == string::npos) pos = n;
int len = pos-start;
maxlen = max(maxlen , len+prelen);
prelen = len;
start = pos+1;
if(pos == n) break;
}
return maxlen;
}

2, Set/Reset a bit in integer

3, reverse print an integer
123 print as 321

4, Remove all spaces in a C strt