Code issue , , , ,, , , , , , , , , , , , , , , , , ,

for(int i=prices.length-1; i>=0; i–)
{
stack.push(prices[i]);
}
int j=0;
int b=0;
int count=1;
while(!stack.isEmpty())
{
int a=stack.pop();
if(a>b)
{
b=a;
prices[j++]=count;
count++;
}
else
{
prices[j++]=1;
}
}


can you check that what is mistake in my code it passing only 2 test cases.

Hey Nitin
Try for this input
5
39
45
40
42
43
correct output: 1 2 1 2 3 END
but your code gives : 1 2 1 1 1 END

sir es question m output ye nhi hona chaiye ki 1 2 1 3 4

kyoki 2 bar profit toh mil chuka h ab jo profit honga usme 1 add ho jaega

sir ek bar question explain krdo samjh nhi aa rha

The span Si of the stock’s price on a given day i is defined as the maximum number of consecutive days just before the given day, for which the price of the stock on the current day is less than or equal to its price on the given day.
For example, if an array of 7 days prices is given as {100, 80, 60, 70, 60, 75, 85}, then the span values for corresponding 7 days are {1, 1, 1, 2, 1, 4, 6}

For computing this problem we will use stack data structure. Time complexity of this method is O(N) where N is the size of stock price array.
In this method S[i] (stock span value) on day i can be easily computed if we know the closest day preceding i, such that the price is greater than on that day than the price on day i.