Real job interview question, find all occurances of a string

Needle is the same:

'join the nmi team'

Giant string can be found in this file in repo of the topicstarter
It starts with line 6 of the file.
I won’t copy it here for the sake of readability :slightly_smiling_face:

@admit8490 I did say “should”. I did not test it before hand with a large string.

Yeah, I understand. That’s why I decided to test it, I was curious: maybe recursive solution didn’t work because of JS. But apparently Python version doesn’t handle large string also.

I am wondering: is there any trick to modify recursive solution in order to make it work for large haystacks?

I checked something for Python:

import sys

I guess if one does something like(1500 is just example):


Maybe it will be enough? Not sure, never played around these things.

And I guess such moves are not safe in general.

A recursive solution here is just not going to work well with large strings. The solutions shown in the article I posted above are much faster.

1 Like

you came up with this idea yourself? so smart, how did you think to do that? I like this one alot. Thank you.

Yeah, that’s from my head. But I don’t think it’s the most effective way to solve it, i still think that there is some advanced math which may be helpful. By my maths skills are not good enough to figure it out.

I used this approach before, to solve one of the Euler problems. I believe it was this one:

There I was also passing some values(like ‘weights’ here) through some… structure I guess, and then collected result in the final destination.

well, I was struggling to solve that euler stuff. I felt that I need some counters, but I couldn’t figure out how to implement them, and just experimenting… and finally something good was created.