Skip to main content

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(map(int, input().split()))
A.sort()
#Telegram - @PLACEMENTLELO
C = [0] * (n + 1)
for i in range(n):
C[i + 1] = C[i] + A[i]
#Telegram - @PLACEMENTLELO
def sum(l, r):
return C[r+1] - C[l]

#Telegram - @PLACEMENTLELO
for q in Q:
p = bisect_left(A, q)
print(sum(p, n-1) - sum(0, p-1) + q * (2 * p - n), end=' ')
#Telegram - @PLACEMENTLELO

-------------------------------------------
Share this with your friends and help them !!



Comments

Post a Comment

Popular posts from this blog

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

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