Today I attempted https://leetcode.com/problems/campus-bikes-ii/ problem on Leetcode.

**This the first solution that I come up with:**

```
public int assignBikes(int[][] workers, int[][] bikes) {
return assignBikes(workers, bikes, 0, new HashSet<>());
}
public int assignBikes(int[][] workers, int[][] bikes, int bike, Set<Integer> assignedWorkers) {
if (assignedWorkers.size() == workers.length) {
return 0;
}
if (bike == bikes.length) return MAX_VALUE;
int ans = assignBikes(workers, bikes, bike + 1, assignedWorkers);
for (int i = 0; i < workers.length; i++) {
if (!assignedWorkers.contains(i)) {
assignedWorkers.add(i);
int distance = manhattanDistance(workers[i], bikes[bike]);
int currAns = assignBikes(workers, bikes, bike + 1, assignedWorkers);
if (currAns != MAX_VALUE) {
ans = min(ans, distance + currAns);
}
assignedWorkers.remove(i);
}
}
return ans;
}
int manhattanDistance(int worker[], int bike[]) {
return Math.abs(worker[0] - bike[0]) + Math.abs(worker[1] - bike[1]);
}
```

This solution gives right answer, but I couldn’t figure out what’s the time complexity of this algorithm. In need help in deriving time complexity of this algorithm.

**Another solution I came up with:**

```
public int assignBikesMethod2(int[][] workers, int[][] bikes) {
return assignBikesMethod2(workers, bikes, 0, new HashSet<>());
}
public int assignBikesMethod2(int[][] workers, int[][] bikes, int worker, Set<Integer> assignedBikes) {
if (worker == workers.length) return 0;
int ans = MAX_VALUE;
for (int i = 0; i < bikes.length; i++) {
if (!assignedBikes.contains(i)) {
assignedBikes.add(i);
int distance = manhattanDistance(workers[worker], bikes[i]);
ans = min(ans, distance + assignBikesMethod2(workers, bikes, worker + 1, assignedBikes));
assignedBikes.remove(i);
}
}
return ans;
}
```

This solution also gives right answer, but I couldn’t figure out what’s the time complexity of this algorithm. In need help in deriving time complexity of this algorithm.

Also it would be really great if there are some online sources to learn deriving time complexity of this kind of backtracking solutions, I always struggle with this.