1 testcase is not running

I know which testcase is not running but i dont know how to figure it out.
Pseudo Code for function

public static int[] StockSpanUsingStacks(int[] prices, StacksUsingArrays stack) throws Exception {
int span[] = new int[prices.length];
stack.push(1);
span[0] = stack.top();

	for(int i = 1; i < prices.length; i++) {
		if(prices[i] >= prices[i-1]) {
			stack.push(stack.top() + 1);
		}
		else {
			stack.push(1);
		}
		span[i] = stack.top();
	}

	return span;
}

I myself solved the question with 2 for loops and without using stack.

here is the pseudo code for that

public static int[] StockSpanUsingStacks(int[] prices, StacksUsingArrays stack) throws Exception {
int span[] = new int[prices.length];
stack.push(1);
span[0] = stack.top();
for(int i = 1; i < prices.length; i++) {
int count = 1;
for(int j = i - 1; j >= 0; j–) {
if(prices[j] <= prices[i])
count++;
else
break;
}
span[i] = count;
}
return span;
}

But i am not looking forward to this approach. As there are two for loops and stack is also not used. Please help mw with the solution.

Logic isn’t correct . Try to think it in another way using stack. When we go from day i-1 to i, we pop the days when the price of the stock was less than or equal to price[i] and then push the value of day i back into the stack.Pushing 1 in stack will not work here you have to push and pop indexes of the array prices.

check this out. giving me one testcase wrong.
public static int[] StockSpanUsingStacks(int[] prices, StacksUsingArrays stack) throws Exception {
int arr[] = new int[prices.length];
arr[0] = 1;
stack.push(0);
int time = 0;
int x;
for(int i = 1; i < prices.length; i++) {
time = 0;
while(!stack.isEmpty() && prices[stack.top()] <= prices[i]) {
time = i - stack.top();
stack.pop();
}
if(stack.isEmpty()) {
time = i;
}
stack.push(i);
arr[i] = time+1;
}
return arr;
}

Use separate array for ans . Also you have calculated time in while loop that doesn’t look right . And plz share link to the code .

i have made extra arr[] for ans.

Link to the code :- https://ide.codingblocks.com/s/100740
Made only slight changes in your code and its working. The problem was where you were calculating time.