WA for 2 testcases
what im missing
my code ide: https://ide.codingblocks.com/s/102675
Funky keyboard wrong answer
@Akansha-Singh-2224543271130461
hey akansha your approach required some modification
I am discussion the step which will used in the program
- Make a void function of any name and pass three parameters no of rows i.e i, no of columns j, and a count variable which will counts the step of knight.
Inside a function
give similar condition as was in your code
before that make global 2d array of board of size 10
as int board[10][10]
Now what cases you should handle in your function
like
if( i<0 || i>=10 || j<0 || j>=10 || board [i][j]==0)
return;
unsets the board array by 0
i.e board[i][j]=0;
manage a variable as hi
which will pass to max function with count+1 variable
hi=max(hi,count+1)
now check for all possible position given in the question like
function(condition1,condition2,count+1)
and after all possible moves set the board[i][j]=1
this is backtracking step
Now in main function
take input of board array as similar as your code but your code have character array but this int array
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>board[i][j];
if(board[i][j])
sum++; // sum stroes total number of valid cells on chessboard
}
}
hi=0;
set(0,0,0);
cout<<sum-hi<<"\n";
Thankyou sir it worked