Editorial for SAC '22 Code Challenge 2 P2 - Cookie Sprinkler
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Intended Solution
Maintain a 2D integer array.
For each type query, add to the specified cell.
For each type query, run a nested for-loop to accumulate all the cookies in the rectangle bounded by to .
Time Complexity:
Alternative Solution
Maintain a list of cookies that you have added.
For each type query, add a cookie to that list.
For each type query, loop through that list and sum up all the cookies that are in the rectangle bounded by to .
Time Complexity:
Comments