This sounds tricky. Dynamic memory allocation to grow your position vector is going to run the risk of running out of memory if the racetrack is long. A Mega doesn't have that much RAM, especially if you're going to get positions at 20Hz.
Then the track layout may be a problem - a U-turn near the start may give a false indication that a lap is over.
Then there's the pits. Can you know if you're there for a tyre change or actually on the track racing?
I expect it can be done, but a Due would be nice for speed and memory.