Anyone managed to pass level 1? I am stuck at level 1. Please share the logic.
Anyone managed to pass level 1? I am stuck at level 1. Please share the logic.
Convert the string to an array of integers called FORWARD. Copy and flip the array into REVERSE. Subtract the values of REVERSE, offset by (0..length), pairwise from FORWARD. Then, just keep track of the longest block of zeros (index in FORWARD and length)
corpus: ilikeracecarstoo FORWARD: (8,11,8,10,4,17,0,2,4,2,0,17,19,14,14) REVERSE: (14,14,19,17,0,2,4,2,0,17,4,10,8,11,8)
In this case, the password appears at an offset of 2 REVERSE(2): (0,0,14,14,19,17,0,2,4,2,0,17,4,10,8) SUBTRACTED: (-8,-11,6,4,15,0,0,0,0,0,0,0,-15,-4,-6)
The longest zero block occurs at FORWARD[5] and ends at FORWARD[11]... in other words, racecar.
Should be quicker than brute force.
Anyway, I would still suggest trying for some more time before looking at the solution that that I have provided here - https://gist.github.com/849813 .
The first problem itself took me most of the time. All this time I was trying to come up with a optimal approach (and was stuck in some boundary condition in implementation for Approach 1) until I realized that even a brute force solution will work in this case because of the smaller text input.
https://www.greplin.com/jobs Here is the source of the challenge link which gives you a heads up it's for a job contest.
max((s[start:end] for start in xrange(len(s)) for end in xrange(start, len(s)) if s[start:end]==s[start:end][::-1]), key=len)
I'm stuck on level 3 right now. The way I'm doing it is probably very very stupid, but I think it will work :)
(I'm trying to brute force it. I may look back at this as very very stupid, but we'll see).
This could get filed under: "Ways to denial-of-service Ryan".
Love it. Thanks to whoever set up the challenge.
Just spend a few minutes thinking about what you know about palindromes and what they look like and it shouldn't be too hard to code.
Color me unimpressed.