We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
**what's the problem with this submission they mentioned that,
If there are multiple solutions, you can output any one
?**
usingnamespacestd;boolisOk(vector<vector<int>>&v,inti,intj,intl){//checking row and column simultaneouslyfor(inty=0;y<9;y++)if(v[i][y]==l||v[y][j]==l)return0;i=i-i%3;j=j-j%3;//check sub matrix of 3 x 3for(inty=0;y<3;y++)for(intk=0;k<3;k++)if(v[i+y][j+k]==l)return0;return1;}voidf(vector<vector<int>>&v,string&s){if(s=="11")return;inti,j;for(i=0;i<9;i++){intz=0;for(j=0;j<9;j++)if(v[i][j]==0){z=1;break;}if(z)break;}if(i>=9&&j>=9){s="11";return;}for(intl=1;l<=9;l++){if(isOk(v,i,j,l)){v[i][j]=l;f(v,s);// cout<<"** // ";}if(s=="11")return;elsev[i][j]=0;}}//@1****34$1*intmain(){intt;cin>>t;while(t--){vector<vector<int>>v(9,vector<int>(9));for(inti=0;i<9;i++)for(intj=0;j<9;j++)cin>>v[i][j];strings="00";f(v,s);if(s=="00"){cout<<"Lol! ,we regret to inform you that , there is no solution for your input ";return0;}for(inti=0;i<9;i++){for(intj=0;j<9;j++)cout<<v[i][j]<<" ";cout<<"\n";}}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sudoku
You are viewing a single comment's thread. Return to all comments →
**what's the problem with this submission they mentioned that,