Whats wrong this code.does not pass any test case

public static long hist(int[] arr, StacksUsingArrays stack) throws Exception {

    int i=0;
	int top=0;
	long max=0;
	while(i<arr.length){
		if(stack.isEmpty()||stack.top()<=arr[i]){
			stack.push(i++);
		}
		else{
			top=stack.pop();
			if(stack.isEmpty()){
				long area=i*arr[top];
				if(area>max)
					max=area;
			}
			else{
				long area=arr[top]*(i-stack.top()-1);
				if(area>max)
					max=area;
			}
		}
	}
	while(!stack.isEmpty()){
		top=stack.pop();
		if(stack.isEmpty()){
			long area=i*arr[top];
			if(area>max){
				max=area;
			}
		}
		else{
			long area=arr[top]*(i-stack.top()-1);
			if(area>max)
				max=area;
		}
	}
	return max;
    
}

hi @khans5854 https://www.youtube.com/watch?v=MhQPpAoZbMc you can see this video for implementation. For future reference please save your code on ide.codingblocks.com and share the link.

hi @khans5854 please mark this doubt as resolved.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.