You are viewing a single comment's thread. Return to all comments →
Hi,
I getting timout for some of the test cases(22,23). please correct where i am wrong.
public class Solution {
public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); ArrayList<Integer> arr_plant = new ArrayList<Integer>(); for (int i = 0; i < n; i++) { arr_plant.add(sc.nextInt()); } int result = 0; int days = 0; int length = arr_plant.size() - 1; while (result ==0) { ArrayList<Integer> stack = new ArrayList<Integer>(); int j=0; stack.add(arr_plant.get(0)); result=1; for (int i = 0; i < length; i++) { if (arr_plant.get(i) > arr_plant.get(i + 1) || arr_plant.get(i) == arr_plant.get(i + 1)) { stack.add(arr_plant.get(i + 1)); j++; } else if (arr_plant.get(i) < arr_plant.get(i + 1)) result = 0; } if(result==0){ days++; } arr_plant = (ArrayList<Integer>) stack.clone(); length = j; } System.out.println(days); }
}
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 →
Hi,
I getting timout for some of the test cases(22,23). please correct where i am wrong.
public class Solution {
}