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.
Passing all test cases but exceeding time limit (~5 sec runtime) in a few.
Could someone suggest an alternative approach or improvements to my current solution (C#)?
public static int poisonousPlants(List<int> p)
{
int days = 0;
List<int> plants = p.ToList();
bool finalDay = false;
do
{
int pCount = p.Count;
for (int i = 1; i < pCount; i++)
{
if (p[i - 1] < p[i]) plants.RemoveAt(i - (pCount - plants.Count));
if (i == pCount - 1)
{
if (p.SequenceEqual(plants)) finalDay = true;
else days++; p = plants.ToList();
}
}
} while (!finalDay && p.Count > 1);
return days;
}
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 →
Passing all test cases but exceeding time limit (~5 sec runtime) in a few. Could someone suggest an alternative approach or improvements to my current solution (C#)?