You can use this solution to connect the points with edges and then count the edges:
Selectively join points using geometry nodes
In Blender 4.0 onward you can use a repeat zone like so:
Instead of using a threshold you could just sum up the distances…