Unique-paths-ii

segmentation fault
vector<vector>& obstacleGrid

Please share the code.

Your logic is not right.

Apart from that, you don’t have any base case in your recursive function for (i == n && j == m).

if this is your base case

	if (i == m && j == n) {
		count++;
	}

then it should be,

	if (i == m && j == n) {
		count++;
        return true;   // true or false whatever you want to
	}

As it is zero based indexing, you probably wants it to be like

    if (i == m - 1 && j == n - 1) {     // not m and n
        sol[i][j] = 1;
        count++;
        return true;
    }
    if (i >= m || j >= n) {    // >=
        return false;
    }

Yeah, that’s because your input is all wrong.

Either first increase the size of your vector or do something like

    vector<vector<int>>obstacleGrid = {
        {0, 0, 1},
        {0, 1, 0},
        {0, 0, 0},
    };


    // for(int i=0;i<obstacleGrid.size();i++){
    //     for(int j=0;j<obstacleGrid[0].size();j++){
    //         cin>>obstacleGrid[i][j];
    //     }
    // }
    cout << uniquePathsWithObstacles(obstacleGrid);

Increase size of vector?

Yes, because by default it is 0
So how can you take the input without knowing the size of input???