The Campus Bikes II interview question is a more difficult version of the first assignment problem. Instead of a greedy assignment, you need to find the assignment of bikes to workers that minimizes the total Manhattan distance sum. You are given n workers and m bikes (m >= n). This Campus Bikes II coding problem is a classic optimization task that can't be solved greedily.
Google uses this to evaluate a candidate's mastery of Dynamic Programming and Bitmasking. Because you need to find the absolute minimum across all possible combinations, simple sorting won't work. It tests your ability to represent the state of "available bikes" using a bitmask and how to use recursion with memoization to avoid redundant calculations.
This utilizes the Array, Bitmask, Dynamic Programming interview pattern.
Worker 0, Worker 1. Bike 0, Bike 1.
Master Bitmask DP. It is the standard solution for problems involving "assigning N things to M things" when N and M are small (usually <= 15-20$). If the constraints are small, bitmasking is almost always the intended path.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Beautiful Arrangement | Medium | Solve | |
| Matchsticks to Square | Medium | Solve | |
| Fair Distribution of Cookies | Medium | Solve | |
| Maximum Compatibility Score Sum | Medium | Solve | |
| Minimum Number of Work Sessions to Finish the Tasks | Medium | Solve |