由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Find consecutive repeated string
相关主题
longest repeated substring怎么做?(亚麻刚刚被问到的题)贴一下我google第一轮店面的题目
finds all repeated substrings in the string --- YAHOO interview questionAmazon Interview Question
问问题请教suffix array的问题
请教suffix tree and longest repeated substringMS SDET面经
讲个笑话用suffix tree 实现从string中找某些substring的算法 ?
贡献一个朋友在Google的面题一枚。问道老题
G phone interview弱问如何用suffix tree求最长palindrome
攒rp整理面试题(1)string match/text search问个算法题
相关话题的讨论汇总
话题: repeated话题: int话题: str话题: find
进入JobHunting版参与讨论
1 (共1页)
a*******y
发帖数: 1040
1
Write a program which returns true if the given string contains the
consecutive repeated substring .Ex-adabcabcd
here abc is consecutive repeated substring.
这个我想要是用map来存character 的index的话,这个不好弄,因为你遇到duplicate
的时候,你不知道是应该update这个index还是不update这个index,因为后面有可能是
从第一个字母开始也有可能从第一次重复的时候开始
另外可以expand around center来进行,但是这就变成0(n^3)了,有啥好方法没有?
b*******d
发帖数: 750
2

duplicate
可以用修改后的suffix tree么?build suffix是linear time,虽然那个算法非常复杂
,很难一下写出来。但是其上每个node的path(从根开始的path)都是一个substring
。把每个node设计成
node {
char c;
List startPos;// 记录下这个node的从根到该node的path的起始点在原
string的位置。是个list因为可能有很多个这种string。
int pathLen; // 记录下这个node的从根到该弄得的path的长度,即该substring的
length。
}
build suffix tree的时候,如果add node时候,发现该node已经存在,说明该
substring已经存在,如果存在一个startPos + pathLen == curStartPos,说明存在一
个连续repeated的substring。
应该是linear time

【在 a*******y 的大作中提到】
: Write a program which returns true if the given string contains the
: consecutive repeated substring .Ex-adabcabcd
: here abc is consecutive repeated substring.
: 这个我想要是用map来存character 的index的话,这个不好弄,因为你遇到duplicate
: 的时候,你不知道是应该update这个index还是不update这个index,因为后面有可能是
: 从第一个字母开始也有可能从第一次重复的时候开始
: 另外可以expand around center来进行,但是这就变成0(n^3)了,有啥好方法没有?

a*******y
发帖数: 1040
3
这个你怎么写build suffix tree的code?不可能当场完成吧,我觉得还得有另外个方
法来写code
b*******d
发帖数: 750
4

写N^2的方法来build suffix tree应该不是很难?

【在 a*******y 的大作中提到】
: 这个你怎么写build suffix tree的code?不可能当场完成吧,我觉得还得有另外个方
: 法来写code

a*******y
发帖数: 1040
5
我就在想有没有更好的办法出了用sufix tree
写了个傻的,不过觉得有更好的
bool strMatch(char* str, int start, int length)
{
for (int i = 0; i {
if (str[start+i] != str[start-length+i])
return false;
}
return true;
}
bool ReturnConsecutiveString(char* str, int n, int& startindex, int&
endindex)
{
int i = 1, j,k;
bool bfail = false;
while (i < n)
{
for (j = 1; (i+j < n) && (i-j-1 >=0);j++)
{
for (k = 0; k<=j;k++)
{
if (strMatch(str, i, k+1))
{
startindex = i;
endindex = i+k;
return true;
}
}


}
i++;
}

return false;
}
a*******y
发帖数: 1040
6
ok, I got it
use a suffix array, then sort it( remember index when you sort), now
repeated substring must occur in neigbor, compare two by two to find two
they have common prefix, and if the common prefix length equal to their
index difference +1 , that would be the answer
1 (共1页)
进入JobHunting版参与讨论
相关主题
问个算法题讲个笑话
[合集] G家onsite面经贡献一个朋友在Google的面题一枚。
suffix tree 和 trieG phone interview
longest common prefix 和 longest common substring攒rp整理面试题(1)string match/text search
longest repeated substring怎么做?(亚麻刚刚被问到的题)贴一下我google第一轮店面的题目
finds all repeated substrings in the string --- YAHOO interview questionAmazon Interview Question
问问题请教suffix array的问题
请教suffix tree and longest repeated substringMS SDET面经
相关话题的讨论汇总
话题: repeated话题: int话题: str话题: find