Editorial for Coding Maniacs contest held on CodeChef dated 17th Oct 2020

Editorial for Coding Maniacs contest held on CodeChef dated 17th Oct 2020

NOTE :

  • 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

  1. Equal Div – ZEP201:­­

Problem Link : CodeChef: Practical coding for everyone

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.

  1. For getting the equal distribution of candies initially, we will divide M by N, and store this value in array of size N.
  2. Now, for getting remaining number of candies take M % N.
  3. 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.
  4. 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.
  5. Finally print the array.

Solution coded in C++ : K0R5OK - Online C++0x Compiler & Debugging Tool - Ideone.com

Solution coded in Python : UfscLw - Online Python3 Interpreter & Debugging Tool - Ideone.com

  1. Video-Xor – VIDXOR:­

Problem Link : CodeChef: Practical coding for everyone

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++ : hsDTAW - Online C++0x Compiler & Debugging Tool - Ideone.com

Solution coded in Python : hCVbMe - Online Python3 Interpreter & Debugging Tool - Ideone.com

  1. Army Chief – ZEP203:­

Problem Link : CodeChef: Practical coding for everyone

Approach / Explanation In this problem,

  1. Store the co-ordinates where 2 is located in the given matrix.
  2. 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.

using this formula :
abs (rowPositionOf1 – rowPositionOf2) + abs (columPositionOf1 – columnPositionOf2);

Note : here abs() will take absolute values.

  1. Do this for every position of 1, and calculate minimum of those and output it.

Solution coded in C++ : OLHz0d - Online C++0x Compiler & Debugging Tool - Ideone.com

Solution coded in Python : UIhjCO - Online Python3 Interpreter & Debugging Tool - Ideone.com

  1. Chef wants to drink – CHDRINK:­

Problem Link : CodeChef: Practical coding for everyone

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++ : NRtSWG - Online C++0x Compiler & Debugging Tool - Ideone.com

Solution coded in Python : ZKv9E9 - Online Python3 Interpreter & Debugging Tool - Ideone.com

  1. Chemical reaction – CHEMREC:­

Problem Link : CodeChef: Practical coding for everyone

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++ : qb0edV - Online C++0x Compiler & Debugging Tool - Ideone.com

Solution coded in Python : YJmXkp - Online Python3 Interpreter & Debugging Tool - Ideone.com

  1. Magical Kite – MAGICKIT:­

Problem Link : CodeChef: Practical coding for everyone

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 : QWCK3m - Online Python3 Interpreter & Debugging Tool - Ideone.com

Thanks for participating in this contest, Hope to see you all in our future contests as well!

Join Programmers Army community on Discord here : Discord
As we will be hosting such contests and webinar every month.

Thanks for the contest. Good problems!

Thanks @ameybhavsar :slight_smile: