Skip to main content

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 of only two characters:

• (: Opening bracket

• ): Closing bracket

S is a balanced bracket sequence.


Balanced Brackets Code in Python


def count_balanced_brackets(n, brackets):

    open_count =0

    close_count =0

    count = 0

    for i in range(n):

        if brackets[I]== '(':

            open_count += 1 

        elif brackets[I] == ')':

            close count += 1


        if open_count > 0 and close_count > 0:

            count += 1 

            open_count -=1

            close_count -=1

    return count


XOR Code in Python


def count_pairs(arr, K):

    count = 0

    for i in range(len(arr)):

        for j in range(i+1, len(arr)):

            distance = (arr[i][e] ^ arr[j][e]) + (arr[i][1] ^ arr[j][1])

            if distance == K:

                count + 1

    return count


Diagonal Number code in Python

Determine the diagonal number to which x belongs.




Maximise Equal Number code in Java

Maximise Equal Number code in C++

Diagonal Number code in Java

Diagonal Number code in C++


Balanced Brackets Code in C++

Balanced Brackets Code in Java


XOR Code in C++

XOR Code in Java


That is Perfection Code in C++ 

That is Perfection Code 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 ()...

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

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,...