No any test cases are passing, please check my code

//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;


    
}

@Vipin_coder
take into consideration the long constraints which are failing your code
refer to this here

my logic is correct ??? i changed int to long in my code still getting WA.
please tell the mistakes in my code only.

@aa1 still getting WA by your given code , please check by run it once .

it passes all the test cases for me

but not passing in my course

@aa1 my solution has accepted on leetcode but not in this course.
what should i do?


it does for me
try again after some time

@Vipin_coder
the code is correct .you can try later and move forward for now

@aa1 still getting WA , What should i do. Please help

you can understand the concept and move forward.

but my code is not accepted, please check test cases once

@Vipin_coder
you can try to submit your code here https://hack.codingblocks.com/app/contests/1600/211/problem
the test cases completely satisfy.I’ll get your problem corrected too
but the code is correct and learning that is the main aim :slight_smile:

@aa1 I am using your solution still getting WA.
Please check whats the problem , if everything is fine why i am getting WA?

i tested the previous one again.looks good to me .
try this https://ide.codingblocks.com/s/328991

Hey! @Vipin_coder

Have you solved your problem now? I am also facing the same problem, could not pass the test cases, although the code is giving the correct ans. Can you help me out if you have solved it?

sure, check input code , store the values in long type array instead of int type.

1 Like

@Vipin_coder thanks man. It worked for me.

btw can you tell why we have to take long type array instead of int type, although the constraints are like:
1<=N<=10^6
Height of each bar in histogram <= 10^9

for less than or equal to 10^9, we take int, right?