FastPrepMost Visited Sprint Marker

Most Visited Sprint Marker

Chubb logoChubb● MediumNEW GRADOA
Learn

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[]) → int

Examples

Example 1

n = 5sprints = [2,4,1,3]return = 2

Difference-array range updates reproduce all inclusive sprint visits and preserve the smallest tied marker.

Example 2

n = 3sprints = [1,3]return = 1

Difference-array range updates reproduce all inclusive sprint visits and preserve the smallest tied marker.

Example 3

n = 4sprints = [4,1,4]return = 1

Difference-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.

More Chubb problems

See Chubb hiring insights
public int mostVisitedMarker(int n, int[] sprints) {
    // Write your code here.
}
n5
sprints[2,4,1,3]
expected2
Checking account…