GFG Weekly Coding Contest - 161 Post Analysis | GeeksforGeeks Practice
Вставка
- Опубліковано 27 сер 2024
- Join us for a post-contest analysis with Jay Dalsaniya where we will be discussing the problems from the GFG Weekly Coding Contest - 161. In this session, Jay will be sharing his approach to solving problems and providing valuable insights on how to approach 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 161: practice.geeks...
-----------------------------------------------------------------------------------------
📆 Solve PROBLEM OF THE DAY Daily: practice.geeks...
📖 Master Competitive Programming: practice.geeks...
-----------------------------------------------------------------------------------------
Follow us and stay updated on everything happening in the world of geeks:
📱 Twitter- / geeksforgeeks
📝 LinkedIn- / geeksforgeeks
🌐 Facebook- / geeksforgeeks.org
📷 Instagram- www.instagram....
#GFGPractice #GeeksforGeeks #WeeklyCodingContest #CodingQuestions
#WeeklyCodingContest161 #JayDalsaniya
what the actual hell, skipped the last question conviniently and still call it "post analysis"
++
they are skipping the last problem since past 3 contests don't know why
Bro it is segment tree+prefix sum problem
much better than last post analysis video but why question 4 is missing
Get Segments
class Solution {
public:
int getSegments(vector arr, int n, int x) {
int segments = 1; // Start with at least one segment
int current_or = 0;
for (int i = 0; i < n; ++i) {
current_or |= arr[i];
if (current_or > x) {
// Start a new segment
segments++;
current_or = arr[i]; // Start the new segment with the current element
}
}
return segments;
}
};
We want live stream back, as we can't be able grasp concept properly 😤😤
codes kha hein ??
Odd Minus Prime
class Solution {
public:
long long maximumSum(int n, int k) {
// Step 1: Identify prime numbers up to n using the Sieve of Eratosthenes
vector isPrime(n + 1, true);
isPrime[0] = isPrime[1] = false;
for (int i = 2; i * i
MY approach of max size array
int i=0,j=n-1;
unordered_mapmp;
for(auto i:A){
mp[i]++;
}
priority_queue pq;
for(auto &i:mp){
pq.push(i.second);
}
// Reduce pairs
while (pq.size() > 1) {
int freq1 = pq.top();
pq.pop();
int freq2 = pq.top();
pq.pop();
// If the frequencies are different, push back the difference
if (freq1 > freq2) {
pq.push(freq1 - freq2);
}
}
// If the priority queue is empty, it means all elements were paired off
if (pq.empty()) {
return 0;
}
return pq.top();
Your technique is very intuitive than what he discussed in the solution. The question setters will always have the idea and approach in their mind to solve the problem, the observations he explained in the solution is very hard to come up with during the contest.
For this question I used vector after the unordered map and sorted it instead of using priority queue and then used two pointer approach to iterate on the vector. O(nlogn) approach is far better for this problem.
@@AnikBhowmickaeb exactly, this was my first weekly contest, i could barely solve 1 question half way but had to use cgpt even after test to come up with the right soln, but still it showed me TLE. then i tried this max array diff question and all my approaches are getting tle, i was and i still am so scared if this is the normal level of questions during oa of companies, idk how i'd survive. i cant even imagine coming up with the intuition or approach these problem setters have planned or what he explained in the video, ur comment relaxed me a bit thank you!
why second questions was giving TLE in 0(nlogn) it should not right,
while a[i] can upto 1e9
so it should not submitted in map soln
use unordered map in C++.
you re using sorting extra space in map
great explanation
please add 4th question...
also take much bigger test case.... like N = 15 or 20....(next time)
I was looking for last questions approach...but it's not here..sad
where is part2 @GeeksforGeeksPractice ??
2nd question, i and j being same would never be co prime right?
Why the Map is not working in And is Equal to Or Question because basically we calculating frequency and find counts, so Why using Map given Wrong Answer?
I have same doubt
@@praneeth123-w6w
Test Case - 1 1 1 2 1 1
I think this case will fail with Map as u will count the freq of 1 as 5 and calculate sub array accordingly .
@praneeth123-w6w
Okay Assume this test cases
1. arr = [1,2,2,2,4]
HashMap value will be map ={1:1, 2:3, 4:1}
Now even the total TC should be 9 i.e => [0,0],[1,1],[1,2],[1,2,3],[1,3],[2,2],[2,3],[3,3],[4,4] . * They are the index numbers on 0 based indexing.
But the sum based on HashMap is 1+ 3+ 1 => 5 which is wrong. I hope it helps 😉
coz here in this we want subarray (continuous elements) if u use map it wont be continues ;
long long int ans = n;
for(int i = 0 ; i < n ; i++)
{
long long cnt = 0;
int j = i+1;
while(j < n && arr[j] == arr[i]){
cnt++;
j++;
}
if(cnt > 0)
{
ans += ((cnt)*(cnt+1)/2);
i = j-1;
}
}
return ans;
this might help
@@shriyanshvishwakarma3432 how [1,3] is going to come and i use formula(n(n+1))/2 for each count ?
public static long ANDequalOR(int n, int[] arr) {
// code here
HashMap hmap = new HashMap();
long ans = n;
long same=1;
for(int i=1;i
Question no 4 is missing in the video, please upload the Question no 4 solution video.
158 contest hi uda dia yr tumhaara bus ki nahi to rehna do bol bol ka thak gaya 158 isma bhi 4th missing
Counting N-Digit Numbers with a 7
class Solution {
public:
const int MOD = 1000000007;
// Function to perform modular exponentiation
long long mod_exp(long long base, long long exp, long long mod) {
long long result = 1;
while (exp > 0) {
if (exp % 2 == 1) {
result = (result * base) % mod;
}
base = (base * base) % mod;
exp = exp / 2;
}
return result;
}
int countWays(int n) {
if (n == 1) {
return 1;
}
long long total_numbers = (9 * mod_exp(10, n - 1, MOD)) % MOD;
long long numbers_without_7 = (8 * mod_exp(9, n - 1, MOD)) % MOD;
long long result = (total_numbers - numbers_without_7 + MOD) % MOD;
return result;
}
};
where is hard one
❤️