We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- All Contests
- HourRank 26
- Cloudy Day
- Discussions
Cloudy Day
Cloudy Day
Sort by
recency
|
33 Discussions
|
Please Login in order to post a comment
Here is my very simple solution in c++;
if any one have correct code in c please send me...
Array Manipulation can be solved using a similar technique as the one you probably used to solve this problem.
The problem my initial solution had was not imposing any order in which I deal with each event type. At each location on the line, you should first deal with clouds starting (suddenly being under a cloud). Then you should deal with any towns at that location. And finally deal with clouds ending.
I think the best way to implement this ordering is to make sure the events are sorted in that order. For example, my events were tuples of the form (location, event type, id). event type is either 0, 1, or 2 with 0 representing cloud ending, 1 representing cloud start, and 2 representing town. This works in Python because tuples are ordered lexicographically. So if events have the same location, they will then be ordered based on their event type (and if they have the same event type, they are ordered by id but by that point, it won't matter which order those events are sorted in.)
Another implementation idea that can be combined with the one above is to move the "cloud ending" event from location (y + r) to location (y + r + 1). This can avoid the confusion of having to hold in your head the conflicting ideas of "this cloud is still in effect" and "this cloud needs to go."
This implementation detail doesn't matter as much in this problem since imposing the order in which we deal with each event type means we can just deal with each event as they come up. However it does seem to be a good practice as you might see if you attempt Array Manipulation.
is the sample input given for this question incomplete?
I get just one testcase wrong, any help appreciated ! https://www.hackerrank.com/contests/hourrank-26/challenges/cloudy-day/submissions/code/1306767298