public static int[] StockSpanUsingStacks(int[] prices, StackUsingArrays stack) throws Exception {
int ref=0;
int[] ans=new int[prices.length];
for(int i=0;i<prices.length;i++) {
if(prices[i]>ref) {
stack.push(prices[i]);
ref=prices[i];
}else {
while(!stack.isEmpty()) {
stack.pop();
}
stack.push(prices[i]);
ref=prices[i];
}
ans[i]=stack.size();
}
return ans;
}
Test Case 2 not passing
@Rishabh8488,
you will get a wrong answer for the test case:
Input:
5
1 11 6 16 13
Correct output:
1 2 1 4 1 END
Your Output:
1 2 1 2 1 END
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.