Tap here to switch tabs
Problem
Submissions

Problem: Maximum Gap Between Stations

Try to solve the Maximum Gap Between Stations problem.

Statement

You are given two strings skill of length nn and station of length mm.

There are nn workers where the ithi^{\text{th}} worker requires skill[i]. There are mm stations where the jthj^{\text{th}} station provides station[j].

Each worker must be assigned to an available station such that:

  • The assigned indices form a strictly increasing sequence 0≤p[0]<p[1]<⋯<p[n−1]<m0 \leq p[0] < p[1] < \dots < p[n - 1] < m.

  • station[p[i]] equals skill[i] for all 0≤i<n0 \leq i < n.

The gap between two adjacent assigned stations is p[i+1]−p[i]p[i + 1] - p[i] for 0≤i<n−10 \leq i < n - 1.

Return the maximum possible value of max⁡0≤i<n−1(p[i+1]−p[i])\max_{0 \leq i < n - 1} (p[i + 1] - p[i]) among all valid assignments.

Constraints:

  • skill.length =n= n

  • station.length =m= m

  • 1≤n≤m≤1051 \leq n \leq m \leq 10^5

  • skill and station consist of lowercase English letters.

  • It is guaranteed that a valid assignment exists for every worker.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Gap Between Stations

Try to solve the Maximum Gap Between Stations problem.

Statement

You are given two strings skill of length nn and station of length mm.

There are nn workers where the ithi^{\text{th}} worker requires skill[i]. There are mm stations where the jthj^{\text{th}} station provides station[j].

Each worker must be assigned to an available station such that:

  • The assigned indices form a strictly increasing sequence 0≤p[0]<p[1]<⋯<p[n−1]<m0 \leq p[0] < p[1] < \dots < p[n - 1] < m.

  • station[p[i]] equals skill[i] for all 0≤i<n0 \leq i < n.

The gap between two adjacent assigned stations is p[i+1]−p[i]p[i + 1] - p[i] for 0≤i<n−10 \leq i < n - 1.

Return the maximum possible value of max⁡0≤i<n−1(p[i+1]−p[i])\max_{0 \leq i < n - 1} (p[i + 1] - p[i]) among all valid assignments.

Constraints:

  • skill.length =n= n

  • station.length =m= m

  • 1≤n≤m≤1051 \leq n \leq m \leq 10^5

  • skill and station consist of lowercase English letters.

  • It is guaranteed that a valid assignment exists for every worker.