Coding Ninjas
The first line of input contains two space separated integers N and M, where N is number of rows and M is the number of columns in the matrix.
Each of the following N lines contain M characters. Please note that characters are not space separated.
Print 1 if there is a path which makes the sentence “CODINGNINJA” else print 0.
1 <= N <= 1000
1 <= M <= 1000
Time Limit: 1 second
2 11
CXDXNXNXNXA
XOXIXGXIXJX
1
bool hasPath(vector<vector<char>> &board, int n, int m) { // Write your code here.}
#include <iostream>#include <vector>using namespace std;
#include "solution.h"
int main() { int n, m; cin >> n >> m;
vector<vector<char>> board(n, vector<char>(m));
for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { cin >> board[i][j]; } }
cout << (hasPath(board, n, m) ? 1 : 0);}
Comments
Post a Comment