GFG Weekly coding contest - 125

So... it's 4th of November 2023, 10:53 evening, ed sheeran's 'Bloodstream' is in the background, and just like the perfectionism of this song, I didn't perform in this contest, I remember how I had wasted time in the last problem of geek and candies.

I was like superfast in the first 2 probs and just when I was getting the momentum this idea of finding all the subarrays of size k came to my mind that led to waste 30 mins eventually. The problem was somewhat like the ones that we see in CodeChef. I knew that I could do this but was like left with around 2 mins when the final idea struck my head. I just didn't realise that I could use the dict container as a way to maintain the frequencies of the flavors of candies and then update them accordingly with the help of a 2-pointer approach.

Well, with 2 mins remaining I decided to go for the geekbits instead of trying for the prob. I knew that I would be able to do it, even with that much time, but I was like Geekbits...rank.... Yah, Geekbits!

So I got like 2*5 geekbits, but got a rank of 839. I will be taking tomorrow's contest, and I am gonna grab that by the neck. For sure.

Out of the 4 probs, apart from this candy one, the other 2 were like 2 minutes stuff. And the last one... I think that I just ignored it in the first seen only. I really need a lot practice and knowledge for that level of problems. Also I need to face that level of probs before I hit the next wednesday, cause it's a CodeChef contest day.

I have a Chess tournament on Monday, so monday is gonna be like only the morning part, cause after the tourn. I will be not in any condition to take a prob of any level.

I really am facing difficulty with scheduling things, I am keeping extra stuff as a 2nd level thing and the base stuffs are like 4 in number, with the academics round the corner, I need to keep that in mind too so that I don't have to take all of that at once, bcz I wanna keep things as simple and less complicated, so I am thinking to finish the academic subjects like as soon as possible so that even in the exam time I will have a normal schedule and will be able to schedule lectures in atleast the conceptual subjects like TOC.

I am also taking the DSLA part in the base priors. cause my back hurts because of too much exercise😂

Overall, the problems of the contest are available here:

https://practice.geeksforgeeks.org/contest/gfg-weekly-coding-contest-125 

and the solutions...

Problem - 1

class Solution:
    def generateAdjacencyList(self, V : int , E : int , edges : List[List[int]]) -> List[List[int]]:
        # code here
        # print(edges)
        ans=[set() for i in range(V)]
        for v1,v2 in edges:
            ans[v1].add(v2)
            ans[v2].add(v1)
        # print(ans)
        ans=list(map(sorted,ans))
        return ans

Problem - 2

class Solution:
    #Function to find the smallSum of the given array
    def smallSum(self, arr, k):
        #Write your code here
        ans=0
        for i in range(len(arr)):
            if(arr[i]<arr[(i+1) if(i!=len(arr)-1) else 0]):
                ans+=arr[i]
            else:
                ans+=arr[i]%k
        return ans%(1000000007)

Problem - 3

class Solution:
    def maximizeFlavors(self, n, k, flavors):
        # Code here
       
        tot_flavs=0
        dic1=dict()
       
        for i in range(len(flavors)):
            dic1[flavors[i]]=dic1.get(flavors[i],0)+1
           
        tot_flavs=len(dic1.keys())
        # print(f"Tot_flavs: {tot_flavs}")
       
        # print(dic1)
       
        min_pos=999999999
       
        i,j=0,0
        count=0
        # print(dic1)
        while(j<n):
            if( ((j-i)+1)==k):
                # print(count)
                dic1[flavors[j]]-=1
                if(dic1[flavors[j]]==0):
                    count+=1
                if(count<min_pos):
                    min_pos=count
                j+=1
            elif( ((j-i)+1)<k):
                dic1[flavors[j]]-=1
                if(dic1[flavors[j]]==0):
                    count+=1
                    # print(f"Increased Count: {count} ")
                j+=1    
                   
            else:
                dic1[flavors[i]]+=1
                if(dic1[flavors[i]]==1):
                    count-=1
                    # print(f"Decreased Count: {count} ")
                i+=1
               
                   
        # for i in range(n-(k-1)):
        #     # dis_ct=set()
        #     count=0
        #     dicTemp=dic1.copy()
           
           
        #     for j in range(i,i+k):
        #         # dis_ct.add(flavors[j])
        #         # print(flavors[j])
        #         dicTemp[flavors[j]]-=1
        #         if(dicTemp[flavors[j]]==0):
        #             count+=1
                   
        #     # count will have the number of flavors that are removed completely
        #     if(count<min_pos):
        #         min_pos=count
               
            # if(len(dis_ct)<min_pos):
            #     min_pos=len(dis_ct)
               
            # print()
        # print(min_pos)
       
        return tot_flavs-min_pos




Comments

Popular Posts