GeeksForGeeks - POTD | GFG POTD Answer
قناة بسيطة
1 218
المشتركون
لا توجد بيانات24 ساعات
-97 أيام
-5730 أيام
أرشيف المشاركات
class Solution{
public:
int solve(string &wild, string &pattern, int i, int j, vector<vector<int>> &dp)
{
if(i < 0 && j < 0)
return 1;
if(i < 0 || j < 0)
return 0;
if(dp[i][j] != -1)
return dp[i][j];
if(wild[i] == pattern[j])
return dp[i][j] = solve(wild, pattern, i - 1, j - 1, dp);
if(wild[i] == '?')
return dp[i][j] = solve(wild, pattern, i - 1, j - 1, dp);
if(wild[i] == '*')
return dp[i][j] = (solve(wild, pattern, i - 1, j - 1, dp) solve(wild, pattern, i, j - 1, dp) solve(wild, pattern, i - 1, j, dp));
return dp[i][j] = 0;
}
bool match(string wild, string pattern)
{
vector<vector<int>> dp(wild.size(), vector<int>(pattern.size(), -1));
return solve(wild, pattern, wild.size() - 1, pattern.size() - 1, dp);
}
};
27th December : C++ Solution☝🏼
————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
class Solution {
public:
vector antiDiagonalPattern(vector> matrix)
{
int n=matrix.size();
vector v;
for(int sum=0;sum<=n+n;sum++)
for(int col=min(sum,n-1);col>=0 && sum-col
Repost from GeeksForGeeks - POTD | GFG POTD Answer
⚡️👨🏻💻Canva Pro For Lifetime👨🏻💻⚡️
⚡️ Only At ₹4️⃣9️⃣
🔥 @Canva_pro_lifetime_49
Interested One Contact Here - @N0T3D
26th December : C++ Solution☝🏼
————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
class Solution{
public:
vector<vector<int>> sumZeroMatrix(vector<vector<int>> &a){
int n=a.size(),m=a[0].size();
int area=0,x1=-1,x2=-1,y1=-1,y2=-1;
for(int l=0;l<m;l++){
vector<int>arr(n);
for(int r=l;r<m;r++){
for(int i=0;i<n;i++){
arr[i]+=a[i][r];
}
unordered_map<int,int>mp;mp[0]=-1;
int sum=0,len=0,s=-1,e=-1;
for(int i=0;i<n;i++){
sum+=arr[i];
if(mp.find(sum)!=mp.end()){
if(len<i-mp[sum]){
len=i-mp[sum];
e=i;
s=mp[sum]+1;
}
}
else mp[sum]=i;
}
if(area<len*(r-l+1)){
area=len*(r-l+1);
y1=l;y2=r;
x1=s;x2=e;
}
}
}
vector<vector<int>> ans;
if(x1==-1x2==-1y1==-1||y2==-1) return ans;
for(int i=x1;i<=x2;i++){
vector<int>temp;
for(int j=y1;j<=y2;j++){
temp.push_back(a[i][j]);
}
ans.push_back(temp);
}
return ans;
}
};
⚡👨🏻💻Canva Pro For Lifetime👨🏻💻⚡
⚡ Only At ₹4⃣9⃣
Interested One Contact Here - @N0T3D
25th December : C++ Solution☝🏼
————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
class Solution
{
private:
int solve(vector> &mat, int n)
{
if(n == 2)
{
return (mat[0][0] * mat[1][1] - mat[0][1] * mat[1][0]);
}
int sum = 0;
for(int i = 0; i < mat[0].size(); i++)
{
int mul = 1;
if(i % 2 == 1)
{
mul = -1;
}
// Forming the submatrix
vector> submatrix;
for(int t1 = 1; t1 < n; t1++)
{
vector v;
for(int t2 = 0; t2 < mat[0].size(); t2++)
{
if(t2 != i)
{
v.push_back(mat[t1][t2]);
}
}
submatrix.push_back(v);
}
sum += mul * mat[0][i] * solve(submatrix, n-1);
}
return sum;
}
public:
//Function for finding determinant of matrix.
int determinantOfMatrix(vector > matrix, int n)
{
if(n == 1)
{
return matrix[0][0];
}
if(n == 2)
{
return (matrix[0][0]*matrix[1][1] - matrix[0][1]*matrix[1][0]);
}
return solve(matrix, n);
}
};
24th December : C++ Solution☝🏼
————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
class Solution {
public:
int buyMaximumProducts(int n, int k, int price[]){
//Write your code here
priority_queue<pair<int,int>>pq;
for(int i = 0;i<n;++i) {
pq.push({-price[i],i+1});
}
int ct = 0;
while(!pq.empty()) {
auto curr = pq.top();
pq.pop();
int count = curr.second;
int cost = -1*curr.first;
if(cost <= k) {
while(count--) {
if(k-cost >= 0) {
ct++;
k = k - cost;
}
else break;
}
}
else break;
}
return ct;
}
};
23rd December : C++ Solution☝🏼
————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
class Solution
{
public:
//Function to find all elements in array that appear more than n/k times.
int countOccurence(int arr[], int n, int k) {
unordered_map mp;
for(int i=0;i (n/k) ){
cnt++;
}
}
return cnt;
}
};
22nd December : C++ Solution☝🏼
————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
class Solution{
public:
vector maxMeetings(int N,vector &S,vector &F){
vector ans;
vector>> temp;
for(int i=0;i
21st December : C++ Solution☝🏼
————————————————————
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
class Solution {
public:
int minCandy(int N, vector &ratings) {
vector candy(N,1);
for(int i = 1; iratings[i-1]) candy[i] = candy[i-1] + 1;
else{
int j = i;
while(j>0 && candy[j]>=candy[j-1] && ratings[j]
20th December : C++ Solution☝🏼
————————————————————
Want JAVA ? 👉🏼 /POTD
🙋🏻♂️Discussion ⁉️
Join ✅ @GFG_Answer
class Solution{
public:
int findWinner(int n, int A[]){
int xorr=0;
for(int i=0;i
🔰 PW Coding Contest 🔰
⚡ Registration Fees - Only ₹11
🔥 REGISTER NOW 🔥
➡️ ONLY 3 DAYS LEFT⏳
🔰 Contest -
Solve 3 Questions Fatest Possible To Win Cash Rewards.
Rewards :
🔰 Rank 1 - ₹21000
⚡ Rank 2 - ₹15000
⚡ Rank 3 - ₹5000
⚡ Plus Benefits -
SDE-1 Job Interview Opportunity At PW, And Many More.
#NOT_SPONSORED
