C ++ implementation for the above approach
#include <bits/stdc++.h> NEW_LINE using namespace std ; const int n = 6 ; const int m = 6 ; const int dx [ ] = { 0 , 1 , -1 , 0 } ; const int dy [ ] = { 1 , 0 , 0 , -1 } ;