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.
Thanks, sure, my solution here is basically yours, but without the Pair Object with Pair.count (this passes 24/31 test cases). I'm just trying to figure out what corner case(s) Pair.count is necessary for (I'm sure it is neccessary for some corner cases, I just can't deduce what they are).
// Complete the poisonousPlants function below.staticintpoisonousPlants(int[]plantArr){intmaxDays=0;Stack<Integer>stackAlive=newStack<>();for(intplantArrIdx=plantArr.length-1;plantArrIdx>0;plantArrIdx--){finalintcurPlant=plantArr[plantArrIdx];intcurDyingStreakCount=0;while(!stackAlive.isEmpty()&&stackAlive.peek()>curPlant){// top of stackAlive diesstackAlive.pop();++curDyingStreakCount;}if(curDyingStreakCount>maxDays){maxDays=curDyingStreakCount;}stackAlive.push(curPlant);}returnmaxDays;}
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 →
Thanks, sure, my solution here is basically yours, but without the Pair Object with Pair.count (this passes 24/31 test cases). I'm just trying to figure out what corner case(s) Pair.count is necessary for (I'm sure it is neccessary for some corner cases, I just can't deduce what they are).