This is how I did it last night! Ended up being way slower and the code was much uglier.
That's what I suspected would happen. I think the best optimization is to calculate the list of points for both paths and then convert one of them to a hash table and iterate over the other one and filter out the elements that are not in the hash table. This is complexity O(n) because iterating over one list is O(n) and checking whether a random element exists in a hash table is still O(1). I don't think any smart trick with segments can get a better complexity.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.