GeeksForGeeks - POTD | GFG POTD Answer
Yopiq kanal
π© Channel was restricted by Telegram
Ko'proq ko'rsatish1 218
Obunachilar
Ma'lumot yo'q24 soatlar
-97 kunlar
-5730 kunlar
Postlar arxiv
23rd September : C++ Solution βπΌ
βββββββββββββββββββββ
ππ»ββοΈDiscussion βοΈ
Join β
@GFG_Answer
β‘Watch This - GFG Prizes :
https://youtube.com/shorts/cXzalfyWKJs?feature=share
class Solution{
public:
// Function to find equilibrium point in the array.
// a: input array
// n: size of array
int equilibriumPoint(long long a[], int n)
{
long long left=0, right=0;
for(int i=0;i
22nd September : C++ Solution βπΌ
βββββββββββββββββββββ
ππ»ββοΈDiscussion βοΈ
Join β
@GFG_Answer
β‘Watch This - GFG Prizes :
https://youtube.com/shorts/cXzalfyWKJs?feature=share
class Solution
{
public:
vector find(int arr[], int n , int x )
{
int a=0, b=0;
for(int i=n/2; i>0; i/=2)
while(a+i0; i/=2)
while(b+i
21st September : C++ Solution βπΌ
βββββββββββββββββββββ
ππ»ββοΈDiscussion βοΈ
Join β
@GFG_Answer
class Solution
{
public:
//Function to find the maximum money the thief can get.
int solve(int arr[] , int n , int i , vector& dp){
if(i>=n){
return 0;
}
if(dp[i] != -1){
return dp[i];
}
int amt1 = arr[i] + solve(arr,n,i+2,dp);
int amt2 = solve(arr,n,i+1,dp);
dp[i] = max(amt1,amt2);
return dp[i];
}
int FindMaxSum(int arr[], int n)
{
vector dp(n,-1);
return solve(arr,n,0,dp);
}
};
20th September : C++ Solution βπΌ
βββββββββββββββββββββ
ππ»ββοΈDiscussion βοΈ
Join β
@GFG_Answer
class Solution
{
public:
vector rotate (int n, int d)
{
d=d%16;
int left=((n<>(16-d)))&((1<<16)-1);
int right=((n>>d)|(n<<(16-d)))&((1<<16)-1);
return {left,right};
}
};
19th September : C++ Solution βπΌ
βββββββββββββββββββββ
ππ»ββοΈDiscussion βοΈ
Join β
@GFG_Answer
class Solution
{
public:
unsigned int getFirstSetBit(int n)
{
if (n == 0)
return 0;
return log2(n & -n) + 1;
}
};
18th September : C++ Solution βπΌ
ββββββββββββββββββββ
π₯Java - @GFGPOTD_Java
π±Python - @GFGPOTD_Python
ππ»ββοΈDiscussion βοΈ
Join β
@GFG_Answer
//User function Template for C++
class Solution{
public:
bool isPowerofTwo(long long n){
if (!n) return false;
while (n%2==0){ n/=2;}
return n == 1;
}
};
17th September : C++ Solution βπΌ
ββββββββββββββββββββ
π₯Java - @GFGPOTD_Java
π±Python - @GFGPOTD_Python
ππ»ββοΈDiscussion βοΈ
Join β
@GFG_Answer
class Solution
{
public:
//Function to return list containing first n fibonacci numbers.
vector printFibb(int n)
{
vectorans(n);
ans[0] = 1;
ans[1] = 1;
for(int i = 2; i < n; i++){
ans[i] = ans[i - 1] + ans[i - 2];
}
return ans;
}
};
16th September : C++ Solution βπΌ
ββββββββββββββββββββ
π₯Java - @GFGPOTD_Java
π±Python - @GFGPOTD_Python
ππ»ββοΈDiscussion βοΈ
Join β
@GFG_Answer
class Solution
{
public:
//Function to count the number of ways in which frog can reach the top.
long long countWays(int n)
{
long long int m=1000000007;
vector arr(n+5,0);
arr[1]=1;arr[2]=2;arr[3]=4;
for(int i=4 ; i
15th September : C++ Solution βπΌ
ββββββββββββββββββββ
π₯Java - @GFGPOTD_Java
π±Python - @GFGPOTD_Python
ππ»ββοΈDiscussion βοΈ
Join β
@GFG_Answer
class Solution{
public:
int equalPartition(int N, int arr[])
{
int sum = 0;
for(int i = 0; i < N; i++)
sum += arr[i];
if(sum % 2)
return 0;
sum /= 2;
vector dp(sum + 1, 0);
dp[0] = 1;
for(int i = 0; i < N; i++)
{
for(int j = sum; j >= arr[i]; j--)
{
dp[j] |= dp[j - arr[i]];
}
}
return dp[sum];
}
};
14th September : C++ Solution βπΌ
ββββββββββββββββββββ
π₯Java - @GFGPOTD_Java
π±Python - @GFGPOTD_Python
ππ»ββοΈDiscussion βοΈ
Join β
@GFG_Answer
class Solution{
public:
int perfectSum(int arr[], int n, int sum)
{
const int mod=1e9+7;
vector dp(sum + 1, 0);
dp[0] = 1;
for (int i = 0; i < n; ++i) {
for (int j = sum; j >= arr[i]; --j) {
dp[j] += dp[j - arr[i]];
dp[j] %= mod;
}
}
return dp[sum];
}
};
