4026. Maximum Gap Between Stations
You are given two strings
skillandstationof lengthsnandm, respectively.
skill[i]represents the skill of workeri, andstation[j]represents the skill supported by stationj.You must assign every worker to a distinct station. Let
j_ibe the index of the station assigned to workeri. A valid assignment must satisfy:
station[j_i] == skill[i]for every0 <= i < n.- The assigned station indices must be strictly increasing in worker order, meaning
j_0 < j_1 < ... < j_n - 1.The gap of an assignment is the maximum difference between the station indices assigned to two consecutive workers. In other words, it is
max(j_i - j_i - 1)over all1 <= i < n.If there is only one worker, the gap is 0.
Return the maximum possible gap among all valid assignments. It is guaranteed that at least one valid assignment exists.
1 | class Solution { |