Editorial for Coding Maniacs contest held on CodeChef dated 17th Oct 2020
- It is highly recommended to first just read the explanation of questions that you were not able to solve and then again try to solve that question without going through the solution and after that, if you got stuck in coding then you can see solutions of that question.
- If you do not found solution coded in your preferred language, it is always better to understand core logic and code it out yourself.
Contest Link : https://www.codechef.com/COMS2020
- Equal Div – ZEP201:
Problem Link : https://www.codechef.com/COMS2020/problems/ZEP201
Approach / Explanation : In this problem you are given N friends and M candies, and asked to distribute M candies among N friends, in particular way as mentioned in the question above.
- For getting the equal distribution of candies initially, we will divide M by N, and store this value in array of size N.
- Now, for getting remaining number of candies take M % N.
- After That, if value of equal distribution (as mentioned in point 1) is even we will add all remining candies starting from first and one at a time to our array.
- If value of equal distribution (as mentioned in point 1) is odd we will add all remining candies starting from end and one at a time to our array.
- Finally print the array.
Solution coded in C++ : https://ideone.com/K0R5OK
Solution coded in Python : https://ideone.com/UfscLw
- Video-Xor – VIDXOR:
Problem Link : https://www.codechef.com/COMS2020/problems/VIDXOR
Approach / Explanation In this problem you need to, take XOR of entire array, and store it in a variable(let’s say ans). Then do XOR of ans with 65, you will get required ans.
Solution coded in C++ : https://ideone.com/hsDTAW
Solution coded in Python : https://ideone.com/hCVbMe
- Army Chief – ZEP203:
Problem Link : https://www.codechef.com/COMS2020/problems/ZEP203
Approach / Explanation In this problem,
- Store the co-ordinates where 2 is located in the given matrix.
- Now, iterate through entire matrix and find the positions where 1 is located, then calculate minimum distance between that position of 1 and position of 2.
Note : here abs() will take absolute values.
- Do this for every position of 1, and calculate minimum of those and output it.
Solution coded in C++ : https://ideone.com/OLHz0d
Solution coded in Python : https://ideone.com/UIhjCO
- Chef wants to drink – CHDRINK:
Problem Link : https://www.codechef.com/COMS2020/problems/CHDRINK
Approach / Explanation : we need something to do append, delete, and pop and search operation in O (1) to solve the problem.
So, here we will implement linked list to delete in O (1) and we will use unordered map to search in O (1) an average. We just need to merge the both data structure to obtain such condition.
Solution coded in C++ : https://ideone.com/NRtSWG
Solution coded in Python : https://ideone.com/ZKv9E9
- Chemical reaction – CHEMREC:
Problem Link : https://www.codechef.com/COMS2020/problems/CHEMREC
Approach / Explanation : we just to go for DFS and for one DFS we will need one “Kill_the_code” we just need to take care if the node does not having edges will not use “kill_the_code” and According to the need we will use the “programmer_army” portion.
Solution coded in C++ : https://ideone.com/qb0edV
Solution coded in Python : https://ideone.com/YJmXkp
- Magical Kite – MAGICKIT:
Problem Link : https://www.codechef.com/COMS2020/problems/MAGICKIT
Approach / Explanation : To find weather u is parent of v or v is parent of u we will make flatten tree and check weather in-time of u and in-time of v is collide or not.
If collide that means yes else not so if yes just make segment tree along with lazy propagation and according to that just update and search in the flatten tree.
Solution coded in Python : https://ideone.com/QWCK3m
Thanks for participating in this contest, Hope to see you all in our future contests as well!
Join Programmers Army community on Discord here : https://discord.gg/4yB29d5
As we will be hosting such contests and webinar every month.