Most Visited Sprint Marker
Problem statement
A track has markers 1 through n. For every adjacent pair in sprints, a runner visits every marker in the inclusive interval between those two endpoints, whether moving forward or backward.
Return the smallest marker with the greatest total visit count across all sprints.
Function
mostVisitedMarker(n: int, sprints: int[]) → intExamples
Example 1
n = 5sprints = [2,4,1,3]return = 2Difference-array range updates reproduce all inclusive sprint visits and preserve the smallest tied marker.
Example 2
n = 3sprints = [1,3]return = 1Difference-array range updates reproduce all inclusive sprint visits and preserve the smallest tied marker.
Example 3
n = 4sprints = [4,1,4]return = 1Difference-array range updates reproduce all inclusive sprint visits and preserve the smallest tied marker.
Constraints
1 <= n <= 200000.2 <= sprints.length <= 200000.1 <= sprints[i] <= n.
Source note: Author-written prompt excerpt retained for source fidelity.