例如說像這個問題: http://www.careercup.com/question?id=14711684
Write the code to find lexicographic minimum in a circular array,
e.g. for the array BCABDADAB, the lexicographic mininum is ABBCABDAD.
一個可能的 Linear time algorithm: (copy from CareerCup)
Given string S.
For String S' = SS (append S to itself).
Compute suffix tree (ST) of S'.
Now do a depth first search of ST,
picking the children in lexicographic order.
Pick the first node you find, at depth |S|.
建 suffix tree 可以在 linear time 做到,
不過像 Java 本身的 library 似乎不包含建 suffix tree,
要在不到一個小時的時間 implement 建 suffix tree 的 function,
至少對我而言應該做不到 Orz...
這種情況是否一定要想出其它的解法,
可以跟 interviewr 說假設已經有個建 suffix tree 的 function,
然後 balabala... 嗎? 有機會被接受嗎?
--
Write the code to find lexicographic minimum in a circular array,
e.g. for the array BCABDADAB, the lexicographic mininum is ABBCABDAD.
一個可能的 Linear time algorithm: (copy from CareerCup)
Given string S.
For String S' = SS (append S to itself).
Compute suffix tree (ST) of S'.
Now do a depth first search of ST,
picking the children in lexicographic order.
Pick the first node you find, at depth |S|.
建 suffix tree 可以在 linear time 做到,
不過像 Java 本身的 library 似乎不包含建 suffix tree,
要在不到一個小時的時間 implement 建 suffix tree 的 function,
至少對我而言應該做不到 Orz...
這種情況是否一定要想出其它的解法,
可以跟 interviewr 說假設已經有個建 suffix tree 的 function,
然後 balabala... 嗎? 有機會被接受嗎?
--
All Comments