GfG Weekly Coding Contest - 191 Post Analysis | GeeksforGeeks Practice
Вставка
- Опубліковано 7 лют 2025
- #GeeksforGeeks #GfGPractice #WeeklyCodingContest
Join us for a post-contest analysis with Ayush Tripathi where we will discuss the problems from the GFG Weekly Coding Contest - 191. In this session, Ayush will share his approach to solving problems and provide valuable insights on approaching similar problems in the future.
Whether you participated in the contest or not, this session is a great opportunity to learn new problem-solving techniques and deepen your understanding of data structures and algorithms. You'll have the chance to ask questions and interact with other participants, making this a fun and engaging learning experience.
🏆 Register for the Upcoming GFG Weekly Coding Contest: www.geeksforge...
-----------------------------------------------------------------------------------------
📆 Solve PROBLEM OF THE DAY Daily: www.geeksforge...
📖 Master Competitive Programming: www.geeksforge...
-----------------------------------------------------------------------------------------
Follow us and stay updated on everything happening in the world of geeks:
📱 Twitter- / x.com/geeksfor...
📝 LinkedIn- / / geeksforgeeks
🌐 Facebook- / / geeksforgeeks.org
📷 Instagram- www.instagram....
#GFGPractice #GeeksforGeeks #WeeklyCodingContest #CodingQuestions
#WeeklyCodingContest191 #ayushtripathi
great ayush ❤❤
your same code for the 2nd problem is not working, as everyone was asking about the wrong answer on some test case, and you kept ignoring them and moved on to the 3rd problem. you should have debug the code at the same time but you thought, what if you end up with the same WA. this is not the way that pcd works.
The solution I have provided for the 2nd problem is absolutely correct and passes all the test cases.
Find below :
class Solution {
public:
int longestPalindrome(vector& arr) {
int left = 0, right = arr.size() - 1;
long leftSum = arr[left], rightSum = arr[right];
int res = 0;
while (left < right) {
if (leftSum == rightSum) {
res += 2;
left++;
right--;
leftSum = arr[left];
rightSum = arr[right];
}
else if (leftSum < rightSum) {
left++;
leftSum += arr[left];
}
else {
right--;
rightSum += arr[right];
}
}
if (left == right)
res++;
return res;
}
};
Additionally, it is not feasible to dry run the solution for more than 2 test cases (which I already did); otherwise, the session becomes too long.
However, since the recording will always be available, you can dry run additional examples yourself.
in third question
why we cannot apply dp means
make a string of length n with all A's intially then for each index recurr it 4 times and if u sucessfully made a string then add 1.
This was my thought process tell what is wrong in this.
if for each index we would have 2 choices so it would be something 2^size not only 4
i am saying in last when you multiplied by 4 there it shouldn't be 2^size?
use long long for second question
in 2nd question class Solution {
public:
int longestPalindrome(vector& arr) {
// code here
int ans = 0;
int i = 0,j = arr.size()-1;
int lsum = arr[i],rsum = arr[j];
while(i < j){
if(lsum == rsum){
ans += 2;
i++;
j--;
lsum = arr[i];
rsum = arr[j];
}
else if(lsum < rsum){
i++;
lsum += arr[i];
}
else{
j--;
rsum += arr[j];
}
}
if(i == j) ans++;
return ans;
}
};
why this code is giving wrong ans?