由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 做题了,看看有没有比我更好的解法 (20个包子)
相关主题
最长回文串Longest common string问题
问道算法题Amazon Summer Intern Offer, 发面经
Palindrome那题,OJ上通不过Write a funtion to find out longest palindrome in a given string
Palindrome那题,OJ上通不过请教几道经典题
leetcode上的Longest Palindromic Substring难道不收brute forfind longest palindrome
python搞不定Longest Palindromic Substring啊问个老问题 Longest palindrome in a string
请问一道Leetcode的题:Longest Palindromic SubstringBloomberg面试题
问一个老题 longest palindrome热腾腾的twitter电面经
相关话题的讨论汇总
话题: linear话题: find话题: longest话题: a2话题: current
进入JobHunting版参与讨论
1 (共1页)
s****a
发帖数: 528
1
NUANCE的,我做了3天,给出的解法据面试的说是最好的,为此拿到OFFER
做的不比我差的可以拿20个包子,欢迎讨论
下礼拜给答案
The Fibonacci palindrome problem
s*****e
发帖数: 16824
2
这个题我想过一会,似乎可以搜索a==c,然后向两边延伸,但是我不知道复杂度是多少
,反正应该小于O(n^2).

【在 s****a 的大作中提到】
: NUANCE的,我做了3天,给出的解法据面试的说是最好的,为此拿到OFFER
: 做的不比我差的可以拿20个包子,欢迎讨论
: 下礼拜给答案
: The Fibonacci palindrome problem

s*****n
发帖数: 5488
3
same idea like DP. for lengtth in 3 to n for i = 1 to n.
O(N^2) but this is too obvious.

【在 s*****e 的大作中提到】
: 这个题我想过一会,似乎可以搜索a==c,然后向两边延伸,但是我不知道复杂度是多少
: ,反正应该小于O(n^2).

t*****j
发帖数: 1105
4
这个第一个条件 是说明sequence对称是吗?也就是说必须是回文sequence对吗?

口。
g*******y
发帖数: 1930
5
好久没做题了,为了20个包子,我来试试吧。
从左边开始,看第一个3-tuple,{a0, a1, a2}
maintain the following info:
current best solution length: 0
hash each new number's first occurrence: a0~0, a1~1
case1: current 3-tuple is valid
find a2 in hash table:
if (found) {
current_best = MAX(current_best, |hash[a2] - current index of a2|;
} else {
hash[a2] = current index of a2; // insert a2 into hash table.
}
case2: current 3-tuple is invalid:
possible_best = solution of (a1 ... an);
return MAX(current_best, possible_best);

【在 s****a 的大作中提到】
: NUANCE的,我做了3天,给出的解法据面试的说是最好的,为此拿到OFFER
: 做的不比我差的可以拿20个包子,欢迎讨论
: 下礼拜给答案
: The Fibonacci palindrome problem

x***y
发帖数: 633
6
First of all, find Longest Common extension of sequence(which uses matching
statistics in suffix tree and constant time LCA to find length of longest
substring that start from any positions at 2 string in constant time after
linear preprocsing)
2nd, find all maximal palindromes (which means that if A[i:j] is palindrome,
then A[i-1:j+1] can not be palindrome) in linear time with the help of
suffix tree and Longest Common extension.
3rd, find the segments in the original sequnce that satisfes the 2nd
requirement.
Finally, find segments intersection of the results of 2nd step and 3rd step
that has the middle(1 element or 2) of max palindromes in 2nd step as the
middle of the segment in linear time. We find the intersection segment with
longest length in linear time.
So, total time is linear as each step is linear.
PS: If I'm right, I will donate the baozi to the jobhunting...

【在 s****a 的大作中提到】
: NUANCE的,我做了3天,给出的解法据面试的说是最好的,为此拿到OFFER
: 做的不比我差的可以拿20个包子,欢迎讨论
: 下礼拜给答案
: The Fibonacci palindrome problem

s****a
发帖数: 528
7
Solution is linear O(n).
but how to achieve the best within linear is another question.
E********a
发帖数: 124
8
其实答案就是两句话,
一,找满足条件2的连续的segments。
二,在这些segments中找最长回文 (O(n), prefix-tree + LCA)

【在 s****a 的大作中提到】
: Solution is linear O(n).
: but how to achieve the best within linear is another question.

d*********i
发帖数: 628
9
学习!
b***e
发帖数: 1419
10
I guess the trick you value is that you compress the array:
1. Discard the numbers but only remember the 3 cases by 0, 1 and 2.
2. Compact the array by counting the 3 symbols to form a much short array.
3. Find palindome on the shorter array.

【在 s****a 的大作中提到】
: Solution is linear O(n).
: but how to achieve the best within linear is another question.

s****a
发帖数: 528
11
Is there any better solution than prefix tree and also linear?
Without internet and book, I cannot actually code the prefix-tree
I*********g
发帖数: 93
1 (共1页)
进入JobHunting版参与讨论
相关主题
热腾腾的twitter电面经leetcode上的Longest Palindromic Substring难道不收brute for
加州的老中软工,interview 喜欢问些啥?python搞不定Longest Palindromic Substring啊
leetcode online judge Longest Palindromic Substring memory limit exceeded请问一道Leetcode的题:Longest Palindromic Substring
像Longest Palindromic Substring这种题,面试的时候问一个老题 longest palindrome
最长回文串Longest common string问题
问道算法题Amazon Summer Intern Offer, 发面经
Palindrome那题,OJ上通不过Write a funtion to find out longest palindrome in a given string
Palindrome那题,OJ上通不过请教几道经典题
相关话题的讨论汇总
话题: linear话题: find话题: longest话题: a2话题: current