We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
This problem is very confusingly formulated. What it wants from you is, given a string, find all substrings that represent powers of 2.
There are powers up to 800, that's a 800-bit integer, you ain't going to find one in any language. Hint: use strings.
Then, you're going to need to find lots of substrings in a string. Others mentioned Aho-Corasick. I managed to do it just with tries. Aho-Corasick is essentially tries plus some optimization. So same thing, but simpler.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Two Two
You are viewing a single comment's thread. Return to all comments →
So, for people who are stuck:
This problem is very confusingly formulated. What it wants from you is, given a string, find all substrings that represent powers of 2.
There are powers up to 800, that's a 800-bit integer, you ain't going to find one in any language. Hint: use strings.
Then, you're going to need to find lots of substrings in a string. Others mentioned Aho-Corasick. I managed to do it just with tries. Aho-Corasick is essentially tries plus some optimization. So same thing, but simpler.