2013年阿里巴巴校园招聘笔试+面试题

hackbuteer1 2012-09-11 11:29:42
面试题:
1、hash_map 和map的区别是什么? 内部怎么实现的?
2、给你1亿个无序的0--1之间的随机小数(精确到0.001),给定一组N个查询范围[x1,y1] [x2,y2] ......[xi,yi] ......[xn,yn] (xi,yi是0--1之间的小数,xi<=yi,精确到0.001),对于每个查询范围,输出在其范围内的数字的个数。

笔试题:
1、寻找一个字符串中最长的重复子串。 如 abcdabc 最长重复串 是abc
2、给你一个wordsList,包含很多英文词组,然后再给你一个description,让你判断是否有wordsList中的词组在description中出现过。
例如 wordsList []={"apple" , "play boys","school"}
description = "play boy in school";
description 包含了school,应该返回true,并没有包含play boys。
bool check(list<string> wordsList, string description);
这个没什么好说的,暴力找出所有子串然后挨个去跟链表里的比较。
3、假设上面的wordsList 的包含的词组很多,长度N很大,而description的长度很小,怎么进行优化? 优化后的时间复杂度是多少??
...全文
8243 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
lm_whales 2013-09-15
  • 打赏
  • 举报
回复
笔试题 3、假设上面的wordsList 的包含的词组很多,长度N很大,而description的长度很小,怎么进行优化? 优化后的时间复杂度是多少?? 调换一下顺序即可 这就是 两个集合求交的算法 原问题(笔试题 2),是A的元素是否在B中. 改为 B的元素,是否在A中即可.
lm_whales 2013-09-15
  • 打赏
  • 举报
回复
共计1001 0.000~1.000 //1001 桶排序或者叫计数排序 O(N)
zyz913614263 2013-09-15
  • 打赏
  • 举报
回复
笔试题一可以二分长度,然后验证解决,复杂素为n(logn)因为 如果长度为l的存在 那么长度为l-1的一定存在
Raise 2013-08-13
  • 打赏
  • 举报
回复
引用 8 楼 cl1_1_1_1 的回复:
[quote=引用 7 楼 smsgreenlife 的回复:] 时间太晚了,今天先帮你写一个,其他的过几天再写。

#include <iostream>
using namespace std;

void substr(char *a)//统计数组a中重复出现的最长的子序列
{	
	for(int n = 0; a[n]!='\0'; ++n);
	int count = 1;
	for (int len=n-1; len>0; --len)//len:子串的长度
	{
		for (int begin=0; begin<=n-1-len; ++begin)//begin:子串的首字符的位置
		{
			for (int match_begin=1; match_begin<=n-len-begin; ++match_begin)//match_begin:匹配字符串与被匹配字符串的距离
			{	
				int i;
				for (i=begin; i<begin+len; ++i)//字符串匹配
				{
					if (a[i]!=a[i+match_begin])
					{
						break;
					}
				}
				if (i==begin+len)//匹配成功
				{
					++count;//统计匹配成功的次数
				}
			}
			if (count>=2)
			{
				for (int i=0; i<len; ++i)
				{
					cout<<a[begin+i];
				}
				return;
			}
			count = 1;
		}
	}
	return;
}

int main(int argc, char* argv[])
{
	char *a = "abcdabc";
	substr(a);
	cout<<endl;
	return 0;
}
请问还有别的答案么? [/quote] 這個可以用LCS算法求最長子串
狼异族 2013-07-12
  • 打赏
  • 举报
回复
笔试题第二题参照Boyer-Moore算法,比暴力快多了
sduxiaoxiang 2013-07-12
  • 打赏
  • 举报
回复
1:hash_map需要hash函数,采用hash表存储,map一般采用红黑树(RB Tree)实现。 2:排序算法 1:动态规划 2、3:trie树
cl1_1_1_1 2013-07-11
  • 打赏
  • 举报
回复
引用 7 楼 smsgreenlife 的回复:
时间太晚了,今天先帮你写一个,其他的过几天再写。

#include <iostream>
using namespace std;

void substr(char *a)//统计数组a中重复出现的最长的子序列
{	
	for(int n = 0; a[n]!='\0'; ++n);
	int count = 1;
	for (int len=n-1; len>0; --len)//len:子串的长度
	{
		for (int begin=0; begin<=n-1-len; ++begin)//begin:子串的首字符的位置
		{
			for (int match_begin=1; match_begin<=n-len-begin; ++match_begin)//match_begin:匹配字符串与被匹配字符串的距离
			{	
				int i;
				for (i=begin; i<begin+len; ++i)//字符串匹配
				{
					if (a[i]!=a[i+match_begin])
					{
						break;
					}
				}
				if (i==begin+len)//匹配成功
				{
					++count;//统计匹配成功的次数
				}
			}
			if (count>=2)
			{
				for (int i=0; i<len; ++i)
				{
					cout<<a[begin+i];
				}
				return;
			}
			count = 1;
		}
	}
	return;
}

int main(int argc, char* argv[])
{
	char *a = "abcdabc";
	substr(a);
	cout<<endl;
	return 0;
}
请问还有别的答案么?
smsgreenlife 2012-09-13
  • 打赏
  • 举报
回复
面试2题计数排序的思想
笔试1题直接求就行了
笔试2题用二分查找的思想,时间复杂度约为O(logn)
smsgreenlife 2012-09-13
  • 打赏
  • 举报
回复
时间太晚了,今天先帮你写一个,其他的过几天再写。

#include <iostream>
using namespace std;

void substr(char *a)//统计数组a中重复出现的最长的子序列
{
for(int n = 0; a[n]!='\0'; ++n);
int count = 1;
for (int len=n-1; len>0; --len)//len:子串的长度
{
for (int begin=0; begin<=n-1-len; ++begin)//begin:子串的首字符的位置
{
for (int match_begin=1; match_begin<=n-len-begin; ++match_begin)//match_begin:匹配字符串与被匹配字符串的距离
{
int i;
for (i=begin; i<begin+len; ++i)//字符串匹配
{
if (a[i]!=a[i+match_begin])
{
break;
}
}
if (i==begin+len)//匹配成功
{
++count;//统计匹配成功的次数
}
}
if (count>=2)
{
for (int i=0; i<len; ++i)
{
cout<<a[begin+i];
}
return;
}
count = 1;
}
}
return;
}

int main(int argc, char* argv[])
{
char *a = "abcdabc";
substr(a);
cout<<endl;
return 0;
}
wutongye 2012-09-12
  • 打赏
  • 举报
回复
笔试题可以先对wordsList建立一棵 Trie 树,然后对description拆分子串来查找 Trie树
zjwzcnjsy 2012-09-11
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

面试题:
1.一个是hash,一个是红黑树?忘了
2.1亿个无序的0--1之间的随机小数(精确到0.001)
int num[1000];//初始化为0
1亿个数乘以1000再num[key]++;
查询的时候也乘以1000查
笔试题:
1.不知道
2.没有说明description多大,子词组是2^N的
3.不知道
[/Quote]
笔试题:2.wordsList遍历一遍到description找?
而对3.是拆description子词组?
zjwzcnjsy 2012-09-11
  • 打赏
  • 举报
回复
面试题:
1.一个是hash,一个是红黑树?忘了
2.1亿个无序的0--1之间的随机小数(精确到0.001)
int num[1000];//初始化为0
1亿个数乘以1000再num[key]++;
查询的时候也乘以1000查
笔试题:
1.不知道
2.没有说明description多大,子词组是2^N的
3.不知道

64,690

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧