r**h 发帖数: 1288 | 1 Yelp这家第一轮HR Screen的时候,HR会问你一些CS方面的基础问题
个人根据自己被问到的经历和玻璃门上的面经总结了一下(实际上没有这么多题不过基
本上都在里面),希望对申请他家的各位有所帮助
1. size of unsigned integer
2. http port no.?
3. ssl full form? (Secure Socket Layer, Encrypt in Transportation layer)
4. use of grep and kill
5. the runtime of adding something to a linked list? O(N)
6. SSL和TLS(Transport Layer Security)的区别:TLS是SSL的升级版(TLS3.0 =
SSL1.0)TLS先handshake再secure
7. hashmaps, DNS(Domain Name System),
8. python native datatypes Boolean, Number, String, Byte, List, ... 阅读全帖 |
|
z*******3 发帖数: 13709 | 2 五个步骤
0)预处理,把输入的string给trim一下,这个适用于任何string作为输入的问题
1)写出is unsigned integer的方法
2)写出is integer的方法,借用步骤1写好的方法,加一个判断是不是+-号开头
3)写出is unsigned double的方法,借用步骤1写好的方法
这里有一个很特殊的corner case,就是.单独出现的情况,其实整个流程就这一个
corner case
4)写出is double的方法,借用步骤3写好的方法
5)然后valid number根据e做切割
e后面必需是integer,用步骤2的方法
e前面必需是double,用步骤4的方法
搞定
看起来很长,其实没啥东西,甚至没有脑筋急转弯的地方,就一个corner case记住就
好了
如果可以自由选择java类库的话,double.parseDouble(String)和integer.parseInt(
String)
加上try catch exception block,简简单单搞定一大串内容
废话说完咯,以下是代码
public class Solution ... 阅读全帖 |
|
s*******s 发帖数: 1031 | 3 follow一下我的面经。
http://www.mitbbs.com/article_t/JobHunting/32517841.html
整理了我的几个解答的算法,分享一下。欢迎批评指正。
多谢!
1. 写一个程序,找出 5^1234566789893943的从底位开始的1000位数字。
我用的递归+数组大数乘法。
// Caclulate (m^n)%(10^k). Keep the k integer numbers in an array.
// Note: the integer numbers are in reversed in the array
// Assume: m>0, n>0, k>0
// Need to check validity outside of this function.
// call calculate(5, 1234566789893943, 1000) to get result.
// Time complexity: O((log n) * k * k)
// Space complexity: O((log n) * k)
ve... 阅读全帖 |
|
j*******o 发帖数: 22 | 4 第一题的unsigned long要改为unsigned long long才行吧 |
|
j*******o 发帖数: 22 | 5 第一题的unsigned long要改为unsigned long long才行吧 |
|
u*****o 发帖数: 1224 | 6 话说我前几天去了学校的campus fair, 看到了nvidia的小booth那里在发卷子做题。现
场那个火爆呀,6个座位永远是满满的,很多人站着答,我才知道这家真是popular呀。
我要了一份卷子,发现好几题都不会。。就没交卷,现在和大家分享一下。因为需要我
一点点打字,所以我只写有点难度的吧。
1. what will be printed by the following code
struct Object{
unsigned char x, y, z, w;
};
int main(){
Object obj;
obj.x = 0x11;
obj.y = 0x22;
obj.z = 0x33;
obj.w = 0x44;
char* p = &obj;
for(int i=0; i<4; i++){
printf("%0xn",*((unsigned short*)++p));
}
return 0;
}
话说这能compile吗? char* p = &obj; 这句用cha... 阅读全帖 |
|
p*****d 发帖数: 126 | 7 我感觉你这个代码由问题。
你的MAX_INT 按照字面上的意思是应该是2的31次方-1
如果value=(2的31次方-1) 而数组中的一个元素是一个负数,比如-2,那diff就等于
负的2的31次方+1,负的值小于0,而实际你想得到的是个正值(2的31次方+1)
diff应该为unsigned 这样能表示的范围会从0到2的32次方-1,如果diff是unsigned的
话value -(-2) 就是可正确的表示了,因为2的31次方+1在0到2的32次方-1内 |
|
p*****d 发帖数: 126 | 8 所以我的macro就很给力啊,我的macro被cast成unsigned了,我的表示空间就大了,不
明白哪里被鄙视了
#define ABSDelta(a,b) ((unsigned int)((((a)>(b))?((a)-(b)):((b)-(a))))) |
|
m*****n 发帖数: 2152 | 9 你这个还是brute force啊。
用bitset<62> key 更好一点吧,或者干脆用unsigned long key,存hash。
用unsigned int value存字长,然后按value排序,从最大开始loop。
如果字长小于sqrt(max),loop就可以停了。
这样的话,最差也是O(n*n*m),最好的话O(n*log(n)*m)。 |
|
D****t 发帖数: 17 | 10 unsigned long long sum = 0;
for(unsigned int i = 1; i < 1000000000; i++)
{
if (i % 3 == 0) continue;
if (i % 227 == 0) continue;
if (i % 14503 == 0) continue;
if (i % 9876543 == 0) continue;
sum += i;
}
cout << "result: " << sum; |
|
y***n 发帖数: 1594 | 11 原题在这里。 http://www.mitbbs.com/article_t/JobHunting/32517841.html 但是觉得不太对
搞这些题觉得很没思路。
// Caclulate (m^n)%(10^k). Keep the k integer numbers in an array.
// Note: the integer numbers are in reversed in the array
// Assume: m>0, n>0, k>0
// Need to check validity outside of this function.
// call calculate(5, 1234566789893943, 1000) to get result.
// Time complexity: O((log n) * k * k)
// Space complexity: O((log n) * k)
vector calculate(unsigned long m, unsigned long n, int k) {
if(... 阅读全帖 |
|
f**********t 发帖数: 1001 | 12 void abc123_(string &s, unsigned left, unsigned right) {
int num = right - left;
if (num < 3) {
return;
}
int mid = (left + right + 1) / 2;
int ll = left + (mid - left) / 2;
int rr = mid + (ll - left);
int i = ll;
for (int k = mid; k < rr; ++i, ++k) {
swap(s[i], s[k]);
}
if (i < mid) {
char temp = s[i];
for (int z = mid; z < rr; ++z) {
s[z - 1] = s[z];
}
s[rr - 1] = temp;
--mid;
}
abc123_(s, left, mid);
abc123_(s, mid, right);
}
void a... 阅读全帖 |
|
C********s 发帖数: 7 | 13 还在这里叫屈的各位,char是8位的,最高位为1时(>127),就变成了负数,除
非你用unsigned char。
所以,就算int cast也不行。因为你用char做index的时候它已经自动做int cast了。
正解是
用unsigned char。
下面这段代码自己拿回去跑一跑就知道了:
#include
int main() {
char c = 255;
int a = c;
printf("%d", a);
} |
|
b****e 发帖数: 985 | 14 May 23-24 -- NFL Spring Meetings - Baltimore, Maryland
June 1 -- Deadline for old clubs to send tender to
unsigned unrestricted free agents to receive
exclusive negotiating rights for rest of season
if player is not signed by another club by
July 15
-- Deadline for old clubs to send tender to
unsigned restricted free agents or to extend
qualify |
|
x****o 发帖数: 21566 | 15 unsigned int contact(constant char *female_id)
{
unsigned int sex = 0;
assert(female_id && female_id == beautiful);
while(!chuchangpian(female_id)) {
sex = paoniu(female_id);
}
sex = celebrate(female_id);
return sex;
} |
|
l***t 发帖数: 81 | 16 Create a function foo() that takes an unsigned int array and an unsigned int
number N as arguments. It returns the size of the largest sub-array whose s
um of its elements is a multiple of N. The array has less than 10000 element
s and N is less than 1000. This function should be as fast as possible |
|
l********s 发帖数: 358 | 17 I'd like to use new() in C++ style.
unsigned *j;
j = new unsigned(0); |
|
O*******d 发帖数: 20343 | 18 给一个C语言的code,可以检查endianess
#include
int main(int argc, char** argv)
{
int a = 0xAABBCCDD;
unsigned char* p = (unsigned char*)&a;
if(p[0] == 0xAA)
printf("Is big endian\n");
else if(p[0] == 0xDD)
printf("Is little endian\n");
else
printf("unknonw endianess\n");
return 0;
} |
|
a***s 发帖数: 1084 | 19 hope this works :
CREATE TEMPORARY TABLE tmp (
customerID INT(10) UNSIGNED DEFAULT '1' NOT NULL auto_increment,
statID INT(10) unsigned default '0' NOT NULL,
);
LOCK TABLES log read;
INSERT INTO tmp select customerID , count(*) from log where typeID = 1
group by customerID ;
SELECT custormerID FROM tmp
WHERE statID > 1 ;
UNLOCK TABLES;
DROP TABLE tmp; |
|
ET 发帖数: 10701 | 20 CREATE TABLE model_by_res (
res_id SMALLINT UNSIGNED NOT NULL,
model_id TINYINT UNSIGNED NOT NULL,
PRIMARY KEY (res_id, model_id),
CONSTRAINT fk_model_by_res_res FOREIGN KEY (res_id) REFERENCES resistor (
res_id) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT fk_model_by_res_model FOREIGN KEY (model_id) REFERENCES res_
model (model_id) ON DELETE RESTRICT ON UPDATE CASCADE
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
dont' know why yah? |
|
t*****z 发帖数: 812 | 21 如果有一个表
id int(10) unsigned not null auto_increment,
name varchar(50) not null,
price int(10) unsigned not null,
primary key ('id')
其中(name,price)必须unique。当我要插入一个数据的时候,我是不是应该先查一
下这个数据
是否已经存在,如果不存在,再执行插入?
有没有其他比较好的办法? |
|
s**********o 发帖数: 14359 | 22 【 以下文字转载自 JobHunting 讨论区 】
发信人: rongxuer (蓉儿), 信区: JobHunting
标 题: 如何秒杀99%的海量数据处理面试题
发信站: BBS 未名空间站 (Thu Apr 5 02:08:57 2012, 美东)
海量数据处理:十道面试题与十个海量数据处理方法总结
作者:July、youwang、yanxionglu。
时间:二零一一年三月二十六日
说明:本文分为俩部分,第一部分为10道海量数据处理的面试题,第二部分为10个海量
数据处理的方法总结。
本文之总结:教你如何迅速秒杀掉:99%的海量数据处理面试题。有任何问题,欢迎随
时交流、指正。
出处:http://blog.csdn.net/v_JULY_v。
------------------------------------------
第一部分、十道海量数据处理面试题
1、海量日志数据,提取出某日访问百度次数最多的那个IP。
首先是这一天,并且是访问百度的日志中的IP取出来,逐个写入到一个大文件中
。注意到IP是32位的,最多有个2^32个IP。同样可以采用映射的... 阅读全帖 |
|
z********i 发帖数: 60 | 23 but how can I write 255 for in a byte. Java has no unsigned int, unsigned
byte..right? Thanks |
|
i**p 发帖数: 902 | 24 先看这个函数的定义。
-------------------------
unsigned long copy_from_user(void *to, const void __user *from, unsigned
long count);
the return value is the amount of memory still to be copied.
-------------------------
to 是由kmalloc()分配的kernel内存空间,假定512字节。
from 是存有数据的内存,其长度是 count 字节。 假定是612字节。
这个函数的返回值是612-512=100,the amount of memory still to be copied。
我的问题是copy_from_user() 执行时,它是怎么知道得"to"的大小呢? |
|
f****y 发帖数: 70 | 25 这种情况怎么debug?
通常为什么会delete出错呢.
比如
unsigned char *buf = new unsigned char[4*4096];
程序最后在deconstruct里有
delete [] buf; 不过到这句就出错了. |
|
m***a 发帖数: 4 | 26 hey, thanks for pointing out that.
but anyone can explain this:
#include
class A
{
public:
static int i;
unsigned char * buf;
int j;
A(){i++; j = i; buf = new unsigned char[4*4096];cout<<"Construction:"<
endl;};
~A(){ delete [] buf;cout<<"Deconstruction:"<
};
int A::i;
main()
{
A a;
A aaa;
aaa = a;
A aaaa = a;
}
the output is
Construction:1
Construction:2
Deconstruction:1
Deconstruction:1
Deconstruction:1
Quite surpring! Why not prompt 'segmentation |
|
P*****f 发帖数: 2272 | 27 来自主题: Programming版 - 一道面试题 I just wonder how to present the value if we donot know the specific "signed
" value. I mean you at least have to use "int" or "unsigned int" to
represent the parameter.
add the largest value of signed value. If it is unsigned, it should be
positive, otherwise, negative. This requires the input more than 0 and less
than max value of signed value. Other cases are easy to check. |
|
j*****h 发帖数: 62 | 28 觉着最优策略首先应该考虑那个'1'在32个bit中的分布.
很多情况下,不是均匀分布的.据个例子,假如一个32位的integer
在整数表示范围内均匀随机分布,试找从右边数第一个出现的'1'位置.
这个问题其实用最笨的办法移位操作来找是很高效的.因为移动次数的
数学期望是小于2的,十来个cycle可以做完(假设branch mispredict).
而如果要查表需要内存访问,cache miss的penalty动辄几百个cycle
是很慢的.
所以,我觉得这道题高效的算法应该避免用查表而内存访问.如果概率分布不均匀
应该相应的制定最有的搜索顺序.假如1在32bit中概率分布是均匀的
用折半查找的方法是很快的,不需要内存访问.
比如下面的算法应该可以在十几个cycle做完.当然还有再提高的余地.
int pos (unsigned int value) {
register unsigned byte tmp;
register int cur;
if (value > 0x10000) {
if (value > 0x1000000)
|
|
t****n 发帖数: 15 | 29 union
{ unsigned char bytes[sizeof(double)];
double value;
}
then manipulate unsigned char member. |
|
p****s 发帖数: 32405 | 30 在C++里,
我尝试着自己定义一个new operator,
首先我这么来一把搞一个带三个参数的new:
#define mynew new (name, type, align)
然后我overload new 和new[]:
void *operator new(size_t size, const char *ModName, memPool_t *memType, size_t alignment) throw();
new[]的overload类似于上.
然后在code里call
pool = mynew(modName, memType, alignment) myPool;
(myPool为自定义的class)
编译的时候出错,compiler不认我定义的这个operator,说
undefined reference to `operator new(unsigned int,char const*,memPool*,unsigned int).
为啥不认呢? 不会是因为我自定义带三个参数的mynew类型和operator new里四个arg
相冲突吧? |
|
O*******d 发帖数: 20343 | 31 来自主题: Programming版 - 数学的美 上边函数用到的几个参数
const unsigned int WIDTH = 1500U;
const unsigned int HEIGHT = 1000U;
const double RATIO = (double)HEIGHT /(double)WIDTH;
/* zoom is calibrated to width 1000 */
const double ZOOM = 0.000000001 * (double)WIDTH / 1000.0 ;
const double ZOOM_Y = ZOOM * RATIO;
const int MAX_ITER = 1800;
/* x and y center of the image */
double xOffset = -0.713;
double yOffset = 0.34; |
|
a****n 发帖数: 20 | 32 下面这个code 有内存泄露吗?
void cpy(Vertex**& d , Vertex**& s, int n_vertices)
{
for ( unsigned int i = 0; i < n_vertices; i++)
{
d[i] = new Vertex(); // 这两句有没有导致内存泄露呢? default
constructor 产
//生的object不是没有指针指着了?
*d[i] = *(s[i]); //
}
}
改成这样是不是就可以了?
void cpy(Vertex**& d , Vertex**& s, int n_vertices)
{
for ( unsigned int i = 0; i < n_vertices; i++)
{
d[i] = new Vertex; // 不用default constructor, 只产生一指针指向一块空
间
*d[i] = *(s[i]) |
|
P********e 发帖数: 2610 | 33 void cpy(Vertex**& d , Vertex**& s, int n_vertices)
{
for ( unsigned int i = 0; i < n_vertices; i++)
{
*d[i] = *(s[i]);
}
}
下面这个code 有内存泄露吗?
void cpy(Vertex**& d , Vertex**& s, int n_vertices)
{
for ( unsigned int i = 0; i < n_vertices; i++)
{
d[i] = new Vertex(); // 这两句有没有导致内存泄露呢? default
constructor 产
//生的object不是没有指针指着了?
*d[i] = *(s[i]); //
}
}
改成这样是不是就可以了?
void cpy(Vertex**& d , Vertex**& s, int n_vertices) |
|
n*******e 发帖数: 55 | 34 电面的时候被问到,自己对hash table不太熟,感觉回答的不是太好,麻烦大家给看一下
要你不用C/C++原有的hash类,自己design一个hash table的class,用伪代码写一个给
这个table赋值和取值的函数,而且已经给了你一个hash function
unsigned int hash(char *), 假设没有任何collision
结果我就卡在怎么样来存储这些index上了,为了实现O(1)的search time,很自然我
会想用数组来做,但是你有不可能浪费这么多内存生成一个2^32(4GB,unsigned int
的range)size的数组。
抱歉本人不是CS的背景,麻烦知道的高手给解释一下?谢谢了 |
|
P********e 发帖数: 2610 | 35 判断100个数全部都抽出是关键
搞4个unsigned int, 128bit中的前100个bit来代表, 0是没抽出,1是抽出
main()
{
unsigned int a[4] = {0,0,0,0};
while(a[0] != ~0 && a[1] != ~0 && a[2] != ~0 && a[3] != 31) {
int ran = rand()%100;
int q/*quotient*/ = ran/32-1;
int r/*remainder*/ = ran%32;
a[q] |= 1 << r;
}
}
I ran the code, it works. |
|
l***8 发帖数: 149 | 36 In M$FT terminology, DWORD is 32-bit unsigned int. WORD is 16-bit unsigned
int. |
|
p**********g 发帖数: 9558 | 37 0,1,2,...127,-128,-127,...-1,0,...
(+1)
char i = -128;
char j = -1;
i = i+j = -128 + -1 = 127;
j = i-j = 127 - -1 = -128;
i = i-j = 127 - -128 = -1;
0,1,2,...255,0,1,2,3,...255,...
(+1)
unsigned char i = 255;
unsigned char j = 1;
i = i+j = 255+1 = 0;
i = i-j = 0-1 = 255;
j = i-j = 0-255= 1; |
|
p*******n 发帖数: 273 | 38 I find in the reference that "size_t is the unsigned integer result of the
sizeof keyword." .
What is that mean? what is the difference between "unsigned int N" and "size
_t N"
Thank you! |
|
mw 发帖数: 525 | 39 我当我把substr的返回值改成实际的变量而不是reference,程序就编译不了了。。。。
请问谁知道是怎么回事吗?
为什么at()里面的throw没法工作呢?
#include
#include
using namespace std;
class mstring{
public:
const char* c_str() const{
return _arr;
}
unsigned int c_len() const{
return _len;
}
void print(){
printf("%s\n", _arr);
}
public:
mstring(){
_len = 0;
_arr = 0;
}
mstring(unsigned int ilen){
_len = ilen;
_ |
|
p****o 发帖数: 1340 | 40 i have a question on operators in c++.
/* header file */
class A;
class B
{
public:
operator A*();
double& operator [](unsigned int);
};
/* cpp file */
B b;
b[3] = 2.2;
the compiler will complain about the "b[3]=2.2" line b/c there are two
possible ways to interpret the code:
1. b.operator[](unsigned) -- my desired operation
2. b.operator A*.operator[] -- which is build-in.
the above code can be compiled and run well under linux, but now i am using
g++ under windows. i just realize suc |
|
h*******e 发帖数: 225 | 41 that's signed shift. there are unsigned shifts too.
for example, in x86 asm, SHL/SHR are unsigned, while SAR/SAL are signed. |
|
G*******n 发帖数: 2041 | 42 I see your point.
char c = 2>>1 | 1<<7; //c = 0x81 = -127
unsigned short b = c;
可以看成是分两步完成的: short temp = c //temp = -127 = 0xff81
unsigned short b = temp; //b = 0xff81 |
|
s*******s 发帖数: 27 | 43 来自主题: Programming版 - 算法题一个 Exactly! Here's the definition of the entry of the linked list.
struct Item{
Item* next;
unsigned int ID;
unsigned int parentID;
}; |
|
s*******s 发帖数: 27 | 44 来自主题: Programming版 - 算法题一个 To build a tree using the following structure
struct Node{
unsigned int ID;
Node** pchildren_array;
unsigned int child_count;
}; |
|
t*****h 发帖数: 137 | 45 I have a following question about unsigned and int type, and the result
really surprised me.
ubuntu 8.04 and g++ 4.24
Here is the code
#include
using namespace std;
int main()
{
unsigned x = 1;
int k = 1;
if ( (x-k) >= -1 )
cout << "0 >= -1\n";
else
{
cout << "0 < -1\n";
}
return 0;
} |
|
g****g 发帖数: 310 | 46 一样的结果,整天讨论哪个快,却自己不去测试一下有意义么?
unsigned long avg1=0, avg2=0;
srand( (unsigned)time( NULL ) );
int j = 0, i=0;
for (int n=0;n<1000000; n++)
{
j = (rand() > RAND_MAX/2) ? 0 : 1;
a = rdtsc();
i+= !(!(j));
b=rdtsc()-a;
avg1+=b;
j=0; i=1;
a = rdtsc();
if( j!=0 ) i++;
b=rdtsc()-a;
avg2+=b;
}
std::cout << "Take:" << avg1/1000000 << std::endl;
std::cout << "Take:" << avg2/1000000 << std: |
|
b***y 发帖数: 2799 | 47 ☆─────────────────────────────────────☆
wmbyhh (wmbyhh) 于 (Sun Jul 6 20:08:03 2008) 提到:
还是以前写的代码,报错stack overflow。
如果去掉里面所有unsigned int为int,define RANGE, N为较小的数如1000,那么编译
就可以正常通过。但是为何不支持unsigned很大的数呢
#include
#include "HeapSort.h"
#include "SelectionSort.h"
#include
#include
#include
#include "MersenneTwister.h"
#define RANGE 1000000 //define the range of input data
#define N 10000000 //define how many random numbers to
generate |
|
b***y 发帖数: 2799 | 48 ☆─────────────────────────────────────☆
TonnyZB (Hallo) 于 (Mon Aug 29 23:26:46 2005) 提到:
I am calling a function of random_number_generator (MT19937) written in C. In
that .c file, the
function is delcared as:
inline unsigned long randomMT(void){
....
}
in my C++ class where I called this function, I declared it as:
extern inline unsigned long randomMT(void);
In the makefile, I also included this .c file. The compilation is OK, but during the linking, it always reported the following
error |
|
n*********i 发帖数: 567 | 49 大致贴一下哈
int main(int argc, char* argv[])
{
HINSTANCE m_DLL;
FP_Open m_Open;
...... // 声明一些函数指针
unsigned int colorspace = 0;
int MemoryLeakTest = 0;
int CrashTest = 0;
bool bDecodeOnly = FALSE;
unsigned char* szRecBuffer = NULL;
Setting mysetting; // 我说的有问题的struct
memset(&mysetting, 0, sizeof(Setting));
//这里就不行了,比如mysetting.a的memset完以后还是0x0a。如果我写mysetting
.a = 2,值还是不变。
.... // 下面是LOAD一个DLL,LOAD FUN |
|