You are viewing a single comment's thread. Return to all comments →
this is the code i used to pass all cases. Its in java though.
import java.util.ArrayList; import java.util.Scanner;
public class PoisonousPlants {
public static void main(String[] args) { // TODO Auto-generated method stub Scanner scn = new Scanner(System.in); ArrayList<Integer> list= new ArrayList(); ArrayList<Integer> stack= new ArrayList(); int n=scn.nextInt(); for(int i=0;i<n;i++){ list.add(i,scn.nextInt()); } int flag=0;int count=0;int days=0;int min=1,max=list.size()-1;int last=0;; boolean first; do{ flag=0; first=true; for(int i=min;i<=max-count&&i<list.size();i++){ if(list.get(i)>list.get(i-1)){ stack.add(i); flag=1; if(first==true) { min=i; first=false; } last=i; } } max=last+1; count=0; while(!stack.isEmpty()){ int z=stack.get(0); list.remove(z-count); stack.remove(0); count++; } days++; }while(flag!=0); System.out.println(days-1); }
}
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 →
this is the code i used to pass all cases. Its in java though.
import java.util.ArrayList; import java.util.Scanner;
public class PoisonousPlants {
}