Skip to main content

Hands of Straights Coding Solution POTD Solution 20 May 2023

Hands of Straights Coding Solution Geeks for Geeks Problem of the Day 20 May 2023

GFG POTD Solution Today 

Gfg problem of the day solution with explanation

C++
class Solution {
  public:
    bool isStraightHand(int n, int k, vector &v) {
        // k= group size
        
        if(n%k>0){
            return false;
        }
        map mp;
        for(auto it:v){
            mp[it]++;
        }
        // put all the size() with its frquency in the (min)p_queue
        priority_queue , vector>, greater> > pq;
        for(auto it:mp){
            pq.push({it.first,it.second});
        }
        int cnt=0;
        int last=-1;
        queue> q;
        while(pq.size()>0){
            int t=pq.top().first;
            int val=pq.top().second;
            pq.pop();
            // take top ele of the heap and check if the last element and 
            // the top element are coincidnt if not return false
            // if yes then put the last ele to curr op element and move forward
            if(val-1>0){
                q.push({t,val-1});
            }
            // unit the group size is not reach dont re push the value of heap by subtracting one from it 
            // to pq again till then put the value in queue
            cnt++;
            if(last>=0){
                if(t-last!=1){
                    return false;
                }else{
                    last=t;
                }
            }
            last=t;
            if(cnt==k){
                while(q.size()>0){
                    pq.push(q.front());
                    q.pop();
                }
                last=-1;
                cnt=0;
            }
        }
        // if int the end it finds that the value of cnt is not 0 means still some element left int group 
        if(cnt>0){
            return false;
        }
        return true;
    }
};

Input: 
N = 9 
groupSize = 3 
hand[ ] = {1, 2, 3, 6, 2, 3, 4, 7, 8} 
Output: true 


Input: 
N = 5 
groupSize = 2 
hand[ ] = {1, 2, 3, 4, 5} 
Output: false 

GFG POTD Answer in C++ 
Gfg problem of the day in python
Gfg problem of the day in java

Comments

Popular posts from this blog

TechGig Code Gladiators 2023 Coding Solutions

TechGig Open Coding Round Code Gladiators 2023 Answers Round 1  - Problem 1 Forest Fire Coding Solution Figure out the minimum energy level P such that they can get exactly X animals to transport.  Test Case: 5 4  1 3 2 4 5 Output: 2 Coding Solution in Python 3: from bisect import bisect_left #Telegram - @PLACEMENTLELO n, m = map ( int , input ().split()) a = list ( map ( int , input ().split())) a.sort() #Telegram - @PLACEMENTLELO if n - bisect_left(a, a[n-m]) != m: print ( -1 ) else : print (a[n - m]) #Telegram - @PLACEMENTLELO ------------------------------------------- Round 2  - Problem 2 The Magic Coding Solution The cost of using wand for operation on element equal to absolute difference between value of element and desired value after operation. Test Case: 5 3 1 2 3 4 5 5 2 1 Output: 10 7 10 Coding Solution in Python 3: from bisect import bisect_left #Telegram - @PLACEMENTLELO n, m = map ( int , input ().split()) A = list ( map ( int , input ().split())) Q = list

The Divisibility Dilemma Code Techgig Geek Goddess Solution

The Divisibility Dilemma Code Techgig Geek Goddess Solution 100% Working Code uploaded on Youtube: https://youtu.be/6cn7nNtSiKo 100% Working Code uploaded on Telegram: https://telegram.me/PLACEMENTLELO The Divisibility Dilemma (100 Marks) In the picturesque village of Numeropolis, the annual "Divisibility Day" is celebrated with great enthusiasm. This day is marked by various mathematical challenges and games that put the villagers' arithmetic skills to the test. This year, the villagers are embarking on a quest to explore the distinctive properties of subarrays within integer arrays. The village's renowned mathematician, Professor Arithmo, has crafted an intriguing challenge. He has provided the villagers with an integer array nums`and two additional integers, K and P. Professor Arithmo's challenge revolves around discovering and counting distinct subarrays from the array nums. The uniqueness of these subarrays is determined by their divisibility characteristics.

Google Girl Hackathon 3 June 2023 Solutions

Google Girl Hackathon 3 June 2023 Solutions Google Girl Hackathon 2023   Maximize equal numbers Code in Python Task Determine the maximum length of the subsequence of array a, such that all numbers in that subsequence are equal after applying the given operation. Code in Python def MaximizeEqualNumber(n, k, a):     #Telegram - @PLACEMENTLELO     max_length = 0     for i in range(n):     #Telegram - @PLACEMENTLELO         count = 1          for x in range(-k, k+1):     #Telegram - @PLACEMENTLELO             if a[i] + x in a[i+1:]:                 count += 1     #Telegram - @PLACEMENTLELO         max_length = max(max_length, count)     return max_length n = 4 k = 1 a = [2, 5, 1, 2] # Output: 3 n = 4 k = 0 a = [2, 2, 5, 6] # Output: 2 n = 3 k = 2 a = [1,5,6] # Output: 2 That is Perfection Code in Python  def is perfect number (n):      divisors_sum = sum(i for i in range(1, n) if n % i == 0)      return divisors_sum == n Balanced Brackets You are given a string S of length N. It consists