简体   繁体   English

字符串运算

[英]String operations

Can anyone help me with this question:.This is not homework,I am preparing for my technical interview. 谁能帮助我解决这个问题:这不是家庭作业,我正在准备我的技术面试。

Given a series of N strings, find a set of repeating string of size 3 eg ababadefb 给定一系列N个字符串,找到一组大小为3的重复字符串,例如ababadefb

I think we might suffer from not knowing the full problem. 我认为我们可能会因不了解全部问题而受苦。 I am going to direct you to a blog entry by a friend of mine where he talks about his interview with Microsoft . 我将把您引到我的一个朋友的博客条目中,他在那儿谈论他对Microsoft的采访

A simple solution would be to construct a Suffix array from the string, sort it and compute the longest common prefix between the current suffix and the one before it. 一种简单的解决方案是从字符串构造后缀数组 ,对其进行排序,然后计算当前后缀和前一个后缀之间的最长公共前缀。 Now all LCPs of length 3 or more will give you the answer (aba in this case). 现在,所有长度为3或更大的LCP都会给您答案(在这种情况下为aba)。

ababadefb 0
abadefb 3
adefb 1
b 0
babadefb 1
badefb 2
defb 0
efb 0
fb 0

As an alternate solution you can build a Radix tree from all suffixes then get all edges that are labeled with strings of length 3 or more. 作为一种替代解决方案,您可以从所有后缀构建一个Radix树 ,然后获取所有标有长度为3或更大的字符串的边。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM