TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Palindromic Rolling Hash (2016)

26 pointsby weird_userover 2 years ago

3 comments

krackersover 2 years ago
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.
thdcover 2 years ago
&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 未加载
eutecticover 2 years ago
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 未加载