GeeksForGeeks - POTD | GFG POTD Answer
Закрытый канал
1 218
Подписчики
Нет данных24 часа
-97 дней
-5730 день
Архив постов
28th June : C++ Solution☝🏼
————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
class Solution {
public:
string pattern(vector<vector<int>> &mat) {
int rows = mat.size();
int col = mat[0].size();
for(int i = 0; i < rows; i++){
int flag = 0;
for(int j = 0; j < col/2; j++){
if(mat[i][j] != mat[i][col - j - 1]){
flag = 1;
break;
}
}
if(flag == 0) return to_string(i) + " R";
}
for(int i = 0; i < col; i++){
int flag = 0;
for(int j = 0; j < rows/2; j++){
if(mat[j][i] != mat[rows - j - 1][i]){
flag = 1;
break;
}
}
if(flag == 0) return to_string(i) + " C";
}
return "-1";
}
};27th June : C++ Solution☝🏼
————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
bool isToeplitz(vector<vector<int>>& mat) {
int n=mat.size();
int m=mat[0].size();
for(int i=0;i<n-1;i++){
for(int j=0;j<m-1;j++){
if(mat[i][j]!=mat[i+1][j+1]){
return false;
}
}
}
return true;
}26th June : C++ Solution☝🏼
————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
class Solution {
public:
int findCoverage(vector<vector<int>>& mat) {
int n=mat.size();
int m=mat[0].size();
int dr[]={1,0,0,-1};
int dc[]={0,-1,1,0};
int ans=0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(mat[i][j]==0){ for(int k=0;k<4;k++){
int newr=i+dr[k];
int newc=j+dc[k];
if(newr>=0 && newr<n && newc>=0 && newc<m && mat[newr][newc]==1){
ans++;
}
}
}
}
}
return ans;
}
};25th June : C++ Solution☝🏼
————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
class Solution {
public:
vector<vector<int>> rotateMatrix(int k, vector<vector<int>> mat) {
int i=0,j=0;
int m = mat.size();
int n = mat[i].size();
vector<vector<int>>v(m, vector<int>(n));
for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
v[i][(j+n-(k%n))%n] = mat[i][j];
}
}
return v;
}
};24th June : C++ Solution☝🏼
————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
class Solution {
public:
long long sumMatrix(long long n, long long q) {
if(q>(2*n)) return 0;
return n-abs(n+1-q);
}
};The Complete Web Developer Course 3.0
⚡ MEGA LINK ⚡
React 🔥
23rd June : C++ Solution☝🏼
————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
class Solution {
public:
vector<int> bracketNumbers(string str) {
stack<int> st;
vector<int> ans;
int p = 1;
for (int i = 0; i < str.size(); i++) {
if (str[i] == '(') {
st.push(p);
ans.push_back(p);
p++;
}
else if (str[i] == ')') {
if (st.empty()) {
ans.push_back(p);
p++;
}
else {
ans.push_back(st.top());
st.pop();
}
}
}
return ans;
}
};22nd June : C++ Solution☝🏼
————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
class Solution{
public:
int kthSmallest(int arr[], int l, int r, int k) {
int n = r-l+1;
sort(arr, arr + n);
return arr[k-1];
}
};The Complete Web Developer Course 3.0
⚡ AVAILABLE ⚡
Will Post On 100 Reacts 🔥🔥🔥
21st June : C++ Solution☝🏼
————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
class Solution {
public:
string compareFrac(string str) {
vector<int> t(4,0);
int comma;
for(int x=0,i=0;i<str.size();i++){
if(str[i]=='/'){
x++; continue;
}
if(str[i]==','){
comma=i;
i++; x++; continue;
}
t[x]=t[x]*10+(str[i]-'0');
}
int p = t[0]*t[3], q = t[1]*t[2];
if(p==q)
return "equal";
if(p>q)
return str.substr(0,comma);
return str.substr(comma+2,str.size());
}
};20th June : C++ Solution☝🏼
————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
