You are viewing a single comment's thread. Return to all comments →
Hi ravi,
I find your solution very close to mine, can you please look into my solution and say if i made any mistake.
I will be curious to know if you got the solution for 23rd input right (Ans 80802)
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); LinkedList<Integer> list = new LinkedList<>(); LinkedList<Integer> stack = new LinkedList<>(); int plants = in.nextInt(); for(int i =0 ; i < plants; i++){ list.push(in.nextInt()); } stack.push(-1); int days =0 ;int temp; while(!list.isEmpty()){ int curr = list.pop(); temp =0; while(stack.peek() > curr){ stack.pop(); temp++; } stack.push(curr); if(temp > days) days = temp; } 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 ravi,
I find your solution very close to mine, can you please look into my solution and say if i made any mistake.
I will be curious to know if you got the solution for 23rd input right (Ans 80802)