TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Palindromic Rolling Hash (2016)

26 点作者 weird_user超过 2 年前

3 条评论

krackers超过 2 年前
It's not novel (I've seen this approach discussed before in competitive programming circles), but it's certainly not too well known. Generally, preprocessing strings via rolling hashes allows you to comparisons in "constant" time.
thdc超过 2 年前
&gt; A palindrome check on this object will take O(1) time for false and O(n) time for true.<p>Someone correct me if I&#x27;m wrong, but this sounds like a suspicious statement to me. If the false case is constant time, then the true (not false) case should also be constant time. In reality, I think the statement should be something like &quot;the palindrome check runs in O(n) time&quot;, but that may ruin the overall runtime by my understanding.<p>I have not looked closely at the implementation.<p>Ok, I thought about it some more and I think the usage of Big-O in that sentence is what confused me. The comparison of two hashes is constant time is my takeaway. The key point of this approach is that it replaces the linear string comparison with the comparison of rolling hashes if I understand correctly, which makes it faster. Sounds relatively unique - as in a nice approach that&#x27;s non-textbook.<p>I believe this kind of thinking is what these kinds of interviewing questions are supposed to look for, rather than regurgitating memorized answers (and pretending you came up with them). But the difficulty spiked due to people gaming the interview which ruined it for the normal non-leetcode-prep engineers.
评论 #34461913 未加载
eutectic超过 2 年前
If you use binary search on the length of the substring then you can get to n log(n) expected time, independent of the input distribution.
评论 #34463380 未加载