Find the Most Visited Track Position
Company: Microsoft
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Overview: Count visits along inclusive sprint intervals in either direction and return the smallest numbered position among those visited most often.
Constraints
- 1 <= n <= 1000000.
- 1 <= sprints.length <= 100000; every sprint position lies between 1 and n.
- Each adjacent pair visits both endpoints and every position between them once, in either direction.
- Shared endpoints count separately for each leg; a stationary leg counts once.
- Return the smallest most-visited position; with no legs, return 1.
Examples
Input: (5, [1, 3, 5])
Expected Output: 3
Explanation: Published sample 1: the shared endpoint 3 receives two visits.
Input: (5, [4, 2])
Expected Output: 2
Explanation: Published sample 2: the inclusive interval 2 through 4 ties, so return 2.