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.
My code without stack passes all test cases logic in the code is pretty simple whenever consecutive plants die you increment the number of days and compare it with max consecutive deaths if max is less update it
here's the code
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution
{
static void Main(String[] args)
{
int n = Int32.Parse(Console.ReadLine());
string[] h1_temp = Console.ReadLine().Split(' ');
int[] h1 = Array.ConvertAll(h1_temp, Int32.Parse);
int min = h1[0];
int mdays = 0;
for (int i = 1; i < n; i++)
{
min = Math.Min(min, h1[i]);
if (h1[i] > h1[i - 1])
{
int l = h1[i];
int k = i+1;
int day = 1;
while (k < n && min < h1[k])
{
if (h1[k] <= l)
{
l = h1[k];
++day;
}
++k;
}
mdays = Math.Max(mdays, day);
}
}
Console.WriteLine(mdays);
}
Poisonous Plants
You are viewing a single comment's thread. Return to all comments →
My code without stack passes all test cases logic in the code is pretty simple whenever consecutive plants die you increment the number of days and compare it with max consecutive deaths if max is less update it
here's the code
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution {
}