InterviewBit Academy is now Scaler!
Learn Tech Skills from Scratch @ Scaler EDGE


What is the worst case time complexity of the following code:

int findMinPath(vector<vector<int> > &V, int r, int c) {
  int R = V.size();
  int C = V[0].size();
  if (r >= R || c >= C) return 100000000; // Infinity
  if (r == R - 1 && c == C - 1) return 0;
  return V[r][c] + min(findMinPath(V, r + 1, c), findMinPath(V, r, c + 1));

Assume R = V.size() and C = V[0].size().

NOTE : This question involves recursion which will be explained later in topic Backtracking. So, if you are not able to approach this question now, you can give it a try later.

Sign Up
to access hints and editorial solutions for REC_CMPL2


Click here to start solving coding interview questions