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 день
Архив постов
class Solution { public: int minSwaps(vector& nums) { int n = nums.size(); int count_one = 0; for(int i=0;i=count_one){ count -= nums[j%n]; j++; zeros = min(zeros,count_one-count); } } return zeros; } };

LeetCode | Daily challenge :

class Solution { public: int dp[100 +1][100 +1]; int editDistance(string str1, string str2) { int n =str1.size(); int m =str2.size(); memset(dp,-1,sizeof(dp)); return memo(str1,str2,n-1,m-1); } int memo(string &s1,string &s2,int i,int j){ if(i == -1){ return j +1; } if(j == -1){ return i +1; } if(dp[i][j] != -1){ return dp[i][j]; } int ins =0,del =0,rep =0; if(s1[i] != s2[j]){ ins = 1 + memo(s1,s2,i,j -1); del = 1 + memo(s1,s2,i -1,j); rep = 1 + memo(s1,s2,i-1,j-1); return dp[i][j] =min(ins,min(del,rep)); }else{ return dp[i][j] =memo(s1,s2,i-1,j-1); } } };

GFG | Problem of the day :

class Solution { public: int countSeniors(vector& d) { vector s; for(int i=0;i60){ cnt++; } } return cnt; } };

LeetCode | Daily challenge :

class Solution { public: vector spirallyTraverse(vector > &matrix) { int n = matrix.size(), m = matrix[0].size(); int dxy[4][2] = {{0,1},{1,0},{0,-1},{-1,0}}; bool vis[n+1][m+1]; memset(vis,false,sizeof(vis)); vector res; int i = 0, j = 0, k = 0; while ( true ){ res.push_back(matrix[i][j]); vis[i][j] = true; if ( res.size() == n*m ) break; int ni = i + dxy[k%4][0], nj = j + dxy[k%4][1]; if ( !(ni >= 0 && ni < n && nj >= 0 && nj < m && !vis[ni][nj]) ) k++; i += dxy[k%4][0]; j += dxy[k%4][1]; } return res; } };

GFG | Problem of the day :

class Solution { private: void floyd_warshell(vector>&dist){ int n = dist.size(); for(int via = 0; via < n; via++){ for(int i=0; i>&dist, int threshold){ int ans = -1, n = dist.size(); int leastCount = INT_MAX; for(int i=0; i>& edges, int distanceThreshold) { vector>distance(n, vector(n, 1e9+7)); for(int i=0; i

LeetCode | Daily challenge :

class Solution { public: bool kPangram(string str, int k) { // code here setst; int count = 0; for(int i=0;i

GFG | Problem of the day :

class Solution { public: vector sortArray(vector& nums) { vector ans; int hash[(int)(1e5+1)] = {}; int k = 5*(1e4); for(auto e:nums) hash[k+e]++; for(int i = 0; i<=2*k; i++){ while(hash[i]-- > 0) ans.push_back(i-k); } return ans; } };

LeetCode | Daily challenge :

class Solution { public: Node* BST(vector<int>&nums,int i,int j){ if(i>j) return NULL; int mid=(i+j)/2; Node* root= new Node(nums[mid]); root->left=BST(nums,i,mid-1); root->right=BST(nums,mid+1,j); return root; } Node* sortedArrayToBST(vector<int>& nums) { return BST(nums,0,nums.size()-1); } };

GFG | Problem of the day :

class Solution { public: struct data { int n; int m; int idx; }; static bool cmp(const struct data &obj1,const struct data &obj2) { if(obj1.m==obj2.m) { return obj1.idx sortJumbled(vector& mapping, vector& nums) { struct data obj[nums.size()]; for(int i=0;i

LeetCode | Daily challenge :

class Solution { public: //Function to check whether a Binary Tree is BST or not. bool validateBST(Node* root, int min, int max){ if(root==NULL){ return true; } if(root->data > min && root->data left, min, root->data); bool right = validateBST(root->right, root->data, max); return left && right; } else{ return false; } } bool isBST(Node* root) { return validateBST(root, INT_MIN, INT_MAX); } };

GFG | Problem of the day :