Stock Span Problem Geeks For Geeks
class StoreStack{ int val; int data; } class Solution { //Function to calculate the span of stock’s price for all n days. public static int[] calculateSpan(int arr[], int n) { ArrayList<Integer> aa=new ArrayList<Integer>(); StoreStack obj[]=new StoreStack[n]; Stack<StoreStack> stack=new Stack<StoreStack>(); for(int i=0;i<n;i++){ obj[i]=new StoreStack(); obj[i].val=arr[i]; obj[i].data=i; } /*for(int i=0;i<n;i++){ System.out.println(obj[i].val+" "+obj[i].data); }*/ for(int i=0;i<n;i++){ if(stack.isEmpty()){ aa.add(-1); } else{ if(stack.peek().val>arr[i]){ aa.add(stack.peek().data); } else{ while(!stack.isEmpty() && stack.peek().val<=arr[i]){ stack.pop(); } if(stack...