ru
Feedback
LeetCode, GeeksForGeeks Problem of the day solution

LeetCode, GeeksForGeeks Problem of the day solution

Открыть в Telegram

Complete daily challenges from LeetCode, GeeksForGeeks and redeem their rewards Channel link : https://t.me/leetcode_gfg_potd

Больше
1 250
Подписчики
+224 часа
+147 дней
+2930 день
Архив постов
GFG | Problem of the day :

class Solution { public: string reverseWords(string s) { int i=0; for(int j=0;j

LeetCode | Daily challenge :

class Solution { public: //Function to return list of integers that form the boundary //traversal of the matrix in a clockwise manner. vector boundaryTraversal(vector > matrix, int n, int m) { vector ans; int row=0; int col=0; while(col =0 && n!=1)ans.push_back(matrix[row][col--]); row--; col++; while(row >0 && m!=1)ans.push_back(matrix[row--][col]); return ans; } };

GFG | Problem of the day :

class Solution { public: bool find132pattern(vector<int>& nums) { int n = nums.size(),m=0; vector<vector<int>> v(2); v[0].push_back(INT_MAX); v[1].push_back(INT_MIN); for(int i=0;i<n;i++){ if((nums[i]>v[0][0] && nums[i]<v[1][0]) || (nums[i]<v[1][m] && nums[i]>v[0][m])) return true; int s=0,l=m; while(l!=s+1 && s!=l){ int mid = (l+s)/2; if(nums[i]>v[0][mid] && nums[i]<v[1][mid]) return true; if(nums[i]<=v[0][mid]) s = mid; else l = mid; } if(v[1][m] == INT_MIN && v[0][m]>nums[i]) v[0][m] = nums[i]; else if(v[1][m]<=nums[i]) v[1][m] = nums[i]; else{ v[0].push_back(nums[i]); v[1].push_back(INT_MIN);m++; } } return false; } };

LeetCode | Daily challenge :

class Solution { public: //Function to modify the matrix such that if a matrix cell matrix[i][j] //is 1 then all the cells in its ith row and jth column will become 1. void booleanMatrix(vector > &matrix) { int n = matrix.size(), m = matrix[0].size(); bool firstRow = false, firstCol = false; for(int c = 0; c < m; c++) if(matrix[0][c] == 1) firstRow = true; for(int r = 0; r < n; r++) if(matrix[r][0] == 1) firstCol = true; for(int i = 1; i < n; i++) for(int j = 1; j < m; j++) if(matrix[i][j]) matrix[0][j] = matrix[i][0] = 1; for(int i = 1; i < n; i++) for(int j = 1; j < m; j++) if(matrix[i][0] || matrix[0][j]) matrix[i][j] = 1; if(firstRow) for(int c = 0; c < m; c++) matrix[0][c] = 1; if(firstCol) for(int r = 0; r < n; r++) matrix[r][0] = 1; } };

GFG | Problem of the day :

class Solution { public: bool isMonotonic(vector& nums) { int n=nums.size(); if(n==1){ return true; } int val1=nums[0]; int val2=nums[n-1]; if(val1>val2){ reverse(nums.begin(), nums.end()); } for(int i=0;i+1nums[i+1]){ return false; } } return true; } };

LeetCode | Daily challenge :

class Solution { public: int numberOfEnclaves(vector> &grid) { int n = grid.size(); int m = grid[0].size(); vector> vis(n, vector(m, 0)); queue> q; for(int i=0;i=0 && row=0 && col

GFG | Problem of the day :

class Solution { public: vector sortArrayByParity(vector& nums) { int oddnum; for(int i = 0; i

LeetCode | Daily challenge :

class Solution{ public: // arr: input array // n: size of array //Function to sort the array into a wave-like array. void convertToWave(int n, vector& arr){ for(int i=0;i+1

GFG | Problem of the day :

class Solution { public: string decodeAtIndex(string s, int k) { long long l = 0, i = 0; while (l < k) { if (isdigit(s[i]))l *= s[i] - '0'; else l++; i++; } for (int j = i - 1; j >= 0; j--) { if (isdigit(s[j])){ l /= s[j] - '0'; k %= l;} else { if (k == 0 || k == l) return string(1, s[j]); l--;} } return ""; } };

LeetCode | Daily challenge :

class Solution{ public: vector printClosest(int arr[], int brr[], int n, int m, int x) { vectorv; int i=0,j=m-1; int res=INT_MAX; while(i=0){ if((x-arr[i]-brr[j])<0){ res=min(res,abs(x-arr[i]-brr[j])); j--; } else if((x-arr[i]-brr[j])>=0){ res=min(res,(x-arr[i]-brr[j])); i++; } } res=x-res; v.push_back(res); return v; } };