# Improbable Challenge Question

• Given the length of a path and a set of back and forth runs on this path, return the position on the path that is visited most often at the end of all runs. If there are multiple positions that meet this criterion, return the lowest position. Example:

Path length: 9
Path positions: 1 2 3 4 5 6 7 8 9
Set of runs: {2, 7, 3, 9, 1, 5}

The set of runs translates to: start at 2, run to 7; start at 7, run to 3; start at 3, run to 9; start at 9, run to 1; start at 1, run to 5. Note that each position is visited once when the run ends there and once when the run starts there, so for example when you run from 2 to 7 and then from 7 to 3, you have visited 7 twice. Given the above example, positions 3, 4 and 5 would all have been visited 5 times, which is the largest number of visits, but the program should return the lowest such positions, which is 3.

How would you do this problem efficiently (not brute-forcing)?

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.