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

КОМЕНТАРІ • 35

  • @ITACHIUCHIHA-dr8sz
    @ITACHIUCHIHA-dr8sz Місяць тому +11

    what the actual hell, skipped the last question conviniently and still call it "post analysis"

  • @sahilshrivastava6455
    @sahilshrivastava6455 Місяць тому +5

    much better than last post analysis video but why question 4 is missing

  • @aayushsharma8170
    @aayushsharma8170 Місяць тому +1

    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;
    }
    };

  • @es_amit
    @es_amit Місяць тому +4

    We want live stream back, as we can't be able grasp concept properly 😤😤

  • @viveksahane1314
    @viveksahane1314 Місяць тому +3

    codes kha hein ??

  • @aayushsharma8170
    @aayushsharma8170 Місяць тому +1

    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

  • @kumkumslab5811
    @kumkumslab5811 Місяць тому +2

    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();

    • @AnikBhowmickaeb
      @AnikBhowmickaeb Місяць тому

      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.

    • @taradean.
      @taradean. Місяць тому +1

      @@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!

  • @kumkumslab5811
    @kumkumslab5811 Місяць тому +1

    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

  • @aizad786iqbal
    @aizad786iqbal Місяць тому

    great explanation
    please add 4th question...
    also take much bigger test case.... like N = 15 or 20....(next time)

  • @deepak3554
    @deepak3554 Місяць тому +1

    I was looking for last questions approach...but it's not here..sad

  • @aizad786iqbal
    @aizad786iqbal Місяць тому

    where is part2 @GeeksforGeeksPractice ??

  • @aizad786iqbal
    @aizad786iqbal Місяць тому

    2nd question, i and j being same would never be co prime right?

  • @inspirationalshorts2689
    @inspirationalshorts2689 Місяць тому +3

    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?

    • @praneeth123-w6w
      @praneeth123-w6w Місяць тому +1

      I have same doubt

    • @sakshampathak1610
      @sakshampathak1610 Місяць тому

      ​​​@@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 .

    • @shriyanshvishwakarma3432
      @shriyanshvishwakarma3432 Місяць тому

      @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 😉

    • @asmitamhetre
      @asmitamhetre Місяць тому

      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

    • @praneeth123-w6w
      @praneeth123-w6w Місяць тому

      @@shriyanshvishwakarma3432 how [1,3] is going to come and i use formula(n(n+1))/2 for each count ?

  • @aizad786iqbal
    @aizad786iqbal Місяць тому

    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

  • @rohithsinghthakur968
    @rohithsinghthakur968 Місяць тому

    Question no 4 is missing in the video, please upload the Question no 4 solution video.

  • @31ankitnain41
    @31ankitnain41 Місяць тому

    158 contest hi uda dia yr tumhaara bus ki nahi to rehna do bol bol ka thak gaya 158 isma bhi 4th missing

  • @aayushsharma8170
    @aayushsharma8170 Місяць тому +1

    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;
    }
    };

  • @prakhargarg4166
    @prakhargarg4166 Місяць тому

    where is hard one

  • @ashutoshgiri2974
    @ashutoshgiri2974 Місяць тому

    ❤️