//please check whats he mistakes in my code
public static long hist(int[] arr, StacksUsingArrays stack)
throws Exception {
int n=arr.length;
int i=0;
long res=0;
for(i=0;i<n;i++){
while(!stack.isEmpty()&&arr[stack.top()]>=arr[i]){
int tp=stack.pop();
int curr=arr[tp]*(stack.isEmpty()?i:(i-stack.top()-1));
res=Math.max(curr,res);
}
stack.push(i);
}
while(!stack.isEmpty()){
int tp=stack.pop();
int curr=arr[tp]*(stack.isEmpty()?n:(n-stack.top()-1));
res=Math.max(res,curr);
}
return res;
}



