All practice tasks

Coding (Algo)

Top Requested Routes

Hash map · Medium

An API dashboard ranks routes by traffic count. Equal counts must produce a stable report across processes.

Return at most k route names sorted by decreasing frequency then ascending ASCII name.

Input

Call

  • Implement solve(input) and return its result. Do not print from solve.

Input object

{ routes:string[], k:integer }

Input rules

  • Route strings are nonempty ASCII paths.

What each field means

  • routes — one route string per request, including repeated requests.
  • k — maximum number of distinct route names to return.

Output

Return value and rules

  • Return up to k distinct routes.
  • Order them by request count descending; break equal-count ties by ASCII route name ascending.
  • Return [] when k is zero or there are no requests.

Constraints

  • 0 <= routes.length <= 100000; 0 <= k <= 100000
  • Route names have at most 80 characters; ordering is not locale-dependent.

Examples

Example 1

{
  "k": 2,
  "routes": [
    "/b",
    "/a",
    "/b",
    "/a",
    "/c"
  ]
}

Returns

[
  "/a",
  "/b"
]

Example 2

{
  "k": 5,
  "routes": []
}

Returns

[]

Required complexity

O(n + u log u) time and O(u) space

What this task practices

Top Requested Routes is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as medium difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.