I think this would work (but I haven't tested it):
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)
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.
I did manage to solve all three problems and I really liked the way the problems were put up on the website.
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.
If you finish you're prompted to submit your code along with your resume for employment consideration. Keep that in mind as you move on to each next step. Had to piece together one of my solutions into a single solution.
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.
Thanks - I might get back to it in a few hours. Currently busy now - I did have 20 minutes to spare earlier and thought a small challenge could be fun.
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.