from Xenny import *

Menu

Category Archives: Code Jam 2014

Full Binary Tree seemed more straightforward to me as compared to Charging Chaos. Right after reading the problem, the solution was almost ready in my mind and I knew that I’ll have to handle the case where a node has more than 2 children.@Full Binary Tree:
We just had to perform DFS on a graph (tree) considering all nodes as root, one at a time, and in that process, choose either 0 or 2 children nodes for every child node. If a node had > 2 children, we had to choose the child with further highest number of children and the child with 2nd highest number of children.
From this problem, I learnt how the parent of a node and its number of children must be stored, when it is required for further computation.

@Charging Chaos:
In , a very careful observation had to be made that only ‘N’ combinations of flips were possible as the bitsets of the devices were fixed, only bitsets of outlets had to be manipulated.
So,
– Get a flip[] combination that matches outlet[0] to the i’th device.
– Apply this combination to rest of the outlets.
– See if the current combination of outlets matches the combination of devices.
– Choose the combination that requires minimum number of flips.

My mistakes during the contest:

1. Even though I was more confident about solving B, I decided to spend time thinking about A. I should have solved B first completely and then come back to A.
2. At times, thoughts about both problems were coming to my mind and I was getting slightly tensed unnecessarily, because I could not find the algorithm to solve A.

Learnings:

1. Focus on the limits of the large dataset and understand what is the expected complexity of the solution.
2. While getting the maximum number from a loop, I used to set values like 123456789 or 99999999 as the initial value. But the safest value to use would be INT_MAX (or other maximum limits as per datatype and limits), just to be safe to prevent small bugs.
3. If we have two std::set< … > containers, we can compare them using the ‘==’ operator.