Tap here to switch tabs
Problem
Submissions

Problem: Campus Bikes II

med
30 min
Try to solve the Campus Bikes II problem.

Statement

On a 2extD2 ext{D} campus grid, there are n workers and m bikes, where each worker and bike is positioned at integer coordinates. You are given two arrays: workers, where workers[i] = [xix_i, yiy_i] represents the position of the ii-th worker, and bikes, where bikes[j] = [xjx_j, yjy_j] represents the position of the jj-th bike.

Each worker must be assigned exactly one unique bike, meaning no two workers may be assigned the same bike.

The Manhattan distance between two locations (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) is defined as ∣x1−x2∣+∣y1−y2∣|x_1 - x_2| + |y_1 - y_2|.

Return the minimum possible sum of Manhattan distances between each worker and their assigned bike.

Constraints:

  • n $= $ workers.length

  • m $= $ bikes.length

  • 1≤1 \leq n ≤\leq m ≤10\leq 10

  • workers[i].length =2= 2

  • bikes[i].length =2= 2

  • 0≤0 \leq workers[i][0], workers[i][1], bikes[i][0], bikes[i][1] <1000< 1000

  • All worker and bike locations are unique.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Campus Bikes II

med
30 min
Try to solve the Campus Bikes II problem.

Statement

On a 2extD2 ext{D} campus grid, there are n workers and m bikes, where each worker and bike is positioned at integer coordinates. You are given two arrays: workers, where workers[i] = [xix_i, yiy_i] represents the position of the ii-th worker, and bikes, where bikes[j] = [xjx_j, yjy_j] represents the position of the jj-th bike.

Each worker must be assigned exactly one unique bike, meaning no two workers may be assigned the same bike.

The Manhattan distance between two locations (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) is defined as ∣x1−x2∣+∣y1−y2∣|x_1 - x_2| + |y_1 - y_2|.

Return the minimum possible sum of Manhattan distances between each worker and their assigned bike.

Constraints:

  • n $= $ workers.length

  • m $= $ bikes.length

  • 1≤1 \leq n ≤\leq m ≤10\leq 10

  • workers[i].length =2= 2

  • bikes[i].length =2= 2

  • 0≤0 \leq workers[i][0], workers[i][1], bikes[i][0], bikes[i][1] <1000< 1000

  • All worker and bike locations are unique.