Test cases failing

problem: https://hack.codingblocks.com/app/contests/2022/502/problem

sol: https://ide.codingblocks.com/s/412766

Hey @raghav007
Initially failing for this type of tcs
5
1 5 2 3 4


 #include<iostream>
#include<stack>
using namespace std;

int i = 0;
int val = 0;
int arr[100000];
int count = 0;//start from 0
void stck(int stock,stack<int> &s){
	s.push(stock);
	if(val <= s.top()){
		count++;//this before next line
		arr[i++] = count;
		val = s.top();
		s.pop();
	}
	else{
		count = 1;
		arr[i++] = count;
		val = s.top();
		s.pop();
	}
}
int main() {
	stack<int> s;
	int n;
	cin>>n;
	int a[100000];
	for(int k = 0; k<n; k++){
		cin>>a[k];
		stck(a[k], s);
	}
	for(int j = 0; j<n; j++){
		cout<<arr[j]<<" ";
	}
	cout<<"END";
	return 0;
}

still one test case is failing

Oh okay there is logical error as well
see for this
5
30
40
35
45
42
Output 1 2 1 4 1 (Re read span definition)