PROBLEM LINK:
Author: Ankush Khanna
DIFFICULTY:
Cakewalk
PREREQUISITES:
PROBLEM:
Given an array with some elements missing, you have to find the missing elements. The missing elements can be found by taking the rounded down average of all the elements traversed before it. The first element is always known.
QUICK EXPLANATION:
Key to AC: Build a prefix sum of the elements traversed so far, whenever we encounter a missing element, take the rounded down average of the current prefix built (till the previous element), update the array element and also the prefix sum. That’s it!
EXPLANATION:
There are two ways of solving this problem. The first one is to just follow what is written in the problem statement (the steps) and solve the sub-task 1 for 30 points. Because it will be a brute force solution working in O(N^2) time, and would certainly fail to pass sub-task 2 within the given time constraint.
The other way is to simply keep a track of the accumulated sum by using prefix sum technique. As mentioned in the quick explanation part, the solution just needs to do the same.
Actually, the quick explanation is the real explanation for this problem. My solution for this problem works in O(N) time per test case, and I have used O(1) auxiliary space for my solution.
COMPLEXITY:
Being a regular cakewalk problem, this problem is also solved in O(N) time per test case. The regular solutions that I have seen have taken O(N) auxiliary space for building the prefix sum, but it can also be done using just constant O(1) auxiliary space.
SOLUTION:
Setter’s Solution [Plain Text]
Feel free to share your approach. If you have any queries, they are always welcome.