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.
What he's trying to do is that: everytime we update the min, those min(s) are the plans that survive. All the plants between the min(s) will eventually die (so he only updates those p[i] > min). The first "if" statements is obvious. For those plans that between 2 min(s) segment:
In order for p[i] to be killed, all the plans p[j] >= p[i] before i must be killed first. So p[i] must wait until the last p[j] is killed. The stack is used to keep track of those that are larger than p[i] before it :).
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Poisonous Plants
You are viewing a single comment's thread. Return to all comments →
What he's trying to do is that: everytime we update the min, those min(s) are the plans that survive. All the plants between the min(s) will eventually die (so he only updates those p[i] > min). The first "if" statements is obvious. For those plans that between 2 min(s) segment: