starters-84 contest Explanations

The Explanations to the Codes provided in the Previous Blog for the Contest Starters-84 of CodeChef:-


Everytime, my interpreter

Digit Operation:-

This was a really weird Question, this was the last one in the contest and there were not many who were able to solve this. Because this looked very complicated but such questions are my favorite bcz this is an array question and that too containing strings in it. I had thought that I will have to do a lot of work in this, but at first I just gave a try by the use of the logic that I initially had seen and I had thought that this will pass some of the Test Cases but I wasn't aware that this will pass all of 'em. Basically the idea is that, if the string in A is of different length than that of B then is no possible way to make them equal. That's it.

Chef and Adjacent Sums:-

This problem looks very cryptic and difficult but believe me it is super easy. Firstly get Z by getting the summation of last 2 elems of sorted input array. Now we just need to see if the input array can be rearranged so no 2 consecutive elems sum up to be >=Z. So, we just use the idea that to get the smallest possible summation between 2 values we pair the smallest with the largest and so on, like 1st elem with the last one in a sorted array, then 2nd elem with 2nd last, and so on. So if in this method we get any summation >=Z then it is not possible else we print Yes if there is not break in the for loop.

Max Count of 

This problem really gave me a tough competition, I passed this one literally in the last 20 secs of the Contest, luckily the last try passed all the Test Cases and I ended up with a score of 6 out of 7 in the contest. Basically, the whole ans depends on what first bit we are taking in the X string so, that cannot be understood in just constant time, we need to consider both the cases( with 1st bit as 1 and as 0 ) that's what I have done in this problem, using the function buzz. Simply, on the basis of 1st bit by comparing with the bits of 's' string I am getting the next bit for the string 'x' although I am not making the string just calculating the no. of ones and returning them from buzz func, the max count of 1 will be printed. Simply, we are going from 0 to n-2 in the string 's'. if the 1st bit was 1 so the count of 1 starts from 1 else starts from 0, then... in the loop, if we get the same bit means the next bit will be 0 so no increase in the count, and the bit_elem is 0 for this case, else count increases and also bit_elem now becomes 1 for being compared to the next bit in 's'.

Elections in Chefland:-

Simply, all those ages which are greater than or equal to the age x will be counted in for Elections. So, for every elem in nums increase count whenever we get a value >= x.

Melt Gold:-

Simply, I am getting the difference b/w x and y. Then count will be increased by 1 inside an infinite while loop and in every iteration this will be added to the temp variable, whenever this temp var becomes >=diff. We break out of the loop and print the number of minutes that were required.

Max Binary:-

Simply, firstly check if the 1st elem is 1, if yes, then we will use all the k operations to add 0's to the end of the string. Else we will check if the string is of size 1 : then just add 1 for the first place(using the 2nd operation) and then use remaining k-1 operations to add 0's to the end.

If string is not of size 1: then, we just make the first elem as 1 and then we leave the remaining string as it is, and add k 0's to the end. That' it!

Comments

Popular Posts