# Help needed in Deriving time complexity of recursive solution to a problem

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)) {
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)) {