Extra question.....help

can u code it fully ??

question -->

hello @hg11110000
pls share the actual question link.

@aman212yadav

@aman212yadav
sorry…this one

@hg11110000
is this going live?

@aman212yadav
no…its over

@aman212yadav

and how is the backtracking working in this…i m not able to catch ???
please explain

these 2 questions please explain…i didn’t get these 2

@hg11110000
have u solved the backtracking problems of ur course.
here they are doing same.
they are trying to reach king if they are able to reach then they r printing yes.
otherwise they r looking for new path.
solve these problems first
a) n queen
b) sudoku solver
c) rat in maze
d) rat chases its cheese.
then only u will able to undertand it well

@aman212yadav
yes i have done backtracking…

but i m not able to solve a new question ??

how to build logic

i was knowing that this is a question of backtracking
but wasnt able to even think
how to approach

can u help please ?

@aman212yadav

how is the flow going…how it is reaching king…
i m not able, to think recursion flow in backtracking questions

bro it comes by practice . first watch all videos(of a particular topic) and get a conceptual clarity and then start practicing .

here if u see the code its pretty much same as rat chases it cheese problem.

int path(int x, int y){
    if(chk[x][y] == 'P'){
        return 0;
    } else if(chk[x][y] == 'K'){
        return 1;
    }
    if(visited[x][y]){
        return 0;
    }
    visited[x][y] = 1;
    int a = check(x-1, y-1);
    int b = check(x-1, y+1);
    int c = check(x+1, y-1);
    int d = check(x+1, y+1);
    int ans = 0;
    if(a){
         ans = max(ans, path(x-1, y-1));
    }
    if(b){
         ans = max(ans, path(x-1, y+1));
    }
    if(c){
         ans = max(ans, path(x+1, y-1));
    }
    if(d){
         ans = max(ans, path(x+1, y+1));
    }
    return ans;
}

this code should make sense to u , we have done similar thing in almost evry btrack problems.
here we reach to a state which contains pawn then obvisously we need to return (to seach for other path this is what we call bactrack)
if we reach to king then we need to return 1 (indicating we reached to the king).
so basically we are trying all moves of knight , if we will find any path then ans will set to 1 otherwise it will remain 0.

are u familiar with dynamic programming?
this question is based on that (count binary string problem of ur course)
this should be ur dp state
dp[i][0]-> ways of i length permuation when electron is placed at i th position
dp[i][1]-> ways of i length permutation when proton us placed at ith position

now simply print dp[n][0]+dp[n][1]

similar types of problem are there in ur course so i recommend to study ur course well