Skip to main content

Posts

Showing posts with the label DSA

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

GEEKS FOR GEEKS WEEKLY CODING CONTEST 103 SOLUTIONS

GEEKS FOR GEEKS WEEKLY CODING CONTEST 103 SOLUTIONS Refueling Code Answer C++ Refueling First GFG Weekly Coding Contest 103 class Solution{     public:     long long refueling(int X)     {         long long a, b;         for(int i=0; i<X; i++){             a = pow(2,i);             if(a == X)return a;             else if(a>X){                 b = pow(2,i-1);                 if(abs(X-a) == abs(X-b))return a;                 if(abs(X-a) < abs(X-b))return a;                 else return b;             }         }         return -1;     } }; Input: X = 3,  Output: 4 Input:  X = 2,  Output: 2 K-Periodic Circular String Code Solution  C++ K-Periodic Circular String Second GFG Weekly Coding Contest 103   class Solution{     public:     string kPeriodic(string s, int K){         // code here         map<char,int> hm;         for(int i=0;i<s.size();i++){           hm[s[i]]++;         }         int n= s.size();         int res= n/__gcd(n,K);              for(auto t:hm

Bus Conductor Coding Solution POTD Solution 21 May 2023

Bus Conductor  Coding Solution Geeks for Geeks Problem of the Day 21 May 2023 You are conductor of a bus ...  Return the minimum number of moves required GFG POTD Solution Today   Gfg problem of the day solution with explanation C++ class Solution {   public:     int findMoves(int n, vector<int> chairs, vector<int> passengers) {      sort(chairs.begin(), chairs.end());      sort(passengers.begin(), passengers.end());            int ans=0;      for(int i=0;i<n;i++){          ans=ans+abs(passengers[i]-chairs[i]);      }      return ans;     } }; Input:  chairs = [3,1,5]  passengers = [2,7,4]  Output: 4 Input:  chairs = [2,2,6,6]  passengers = [1,3,2,6]  Output: 4 GFG POTD Answer in C++   Gfg problem of the day in python  Gfg problem of the day in java

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 eleme

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

Program for Oscillating Prices of Chakri Coding Problem

Oscillating Prices of Chakri Diwali is here. While everyone here is busy texting "Happy Diwali" wishes to everybody else, Coder has some other plans and wants to earn some money this season. Now, the Apex court has allowed the sale of only green crackers this Diwali. Out of all green crackers, "Chakri" is most popular. Because of the irregular supply of "Chakri", the price of "Chakri" is oscillating daily. Coder saw a business opportunity in this. He/She got a price list for coming N days from an insider in the market union. Prices in the list are for 1 unit of a large packet of "Chakri". Each large packet contains 100 units of Chakri. Now, due to financial limitations, Coder can transact only 1 large packet (100 units of "Chakri") in the market. You have to tell maximum profit possible, given that he/she can transact atmost one time. Note: 1. Transaction refers to the act of buying and selling.       2. "Chakri" can

Program for Target Marbles Coding Problem

Target Marbles Coding Problem At a Town, we love to play with marbles. We have many marble games, but the most popular one is “Target Marbles”. Now, our marbles are unique. Each marble has a number on it. In Target Marbles, the player is given a number in the starting and this number is called target. The player is also given N number of marbles to play with. Now, player has to arrange the marbles in a specific way such that sum of the values of at least one of the continuous subset of the arrangement is equal to given target. Now, Coder came to play this game and made an arrangement of marbles. The judges of the game need your help. You have to determine if Coder has won it or not. Input Format : First line contains number of marbles(N) and target (target_number) that was assigned to Coder. Second line contains N space separated integers, which represent arrangement of the marbles and value written on that particular marble. Constraints: 1<= N <=100 1<=target_number<=10000

Program for Village Cricketers Coding Problem

Village Cricketers Coding Problem There are ‘n’ number of villages. You are given an array of size ‘n’ representing the population of each village. Every year, there is a cricket competition between two teams and villagers who come to see the match. Villagers from ith village and (n-i)-1th village (0 <= i < n/2) are combined and then formed groups of 10 people each. For e.g. villagers from villages 0 and n-1, 1 and n-2, 2 and n-3 are combined. The number of villages is always even. So, clearly there will be n/2 combinations from all the villages. You have to tell how many groups will be formed in each combination and how many villagers will be left without the complete group of 10 peoples. Input Format: First-line will have a single integer ‘n’ denotes the number of villages. The second line will have ‘n’ space-separated integers denoting the population of villages. Output format: Print ‘n/2’ lines of two space-separated integers, first will be no. of groups and second will be vi