GeeksforGeeks Problem of the Day
Anonymous user24 Oct 2026
#GeeksforGeeks#GFG POTD#GFG Problem of the Day#GeeksforGeeks POTD Solution
It is recommended to first try at your own. 24 Oct 2026
The GeeksforGeeks POTD solution is given below:
class Solution {
public:
bool isPossible(int n, int m, string& s) {
// code here
int row=0,col=0;
int minRow=0,maxRow=0;
int minCol=0,maxCol=0;
for(char ch:s){
if(ch=='L') col--;
else if(ch=='R') col++;
else if(ch=='U') row--;
else row++;
minRow=min(minRow,row);
minCol=min(minCol,col);
maxRow=max(maxRow,row);
maxCol=max(maxCol,col);
}
int reqRows=maxRow-minRow+1;
int reqCols=maxCol-minCol+1;
return reqRows<=n && reqCols<=m;
}
};