i’m unable to understand when its get complied successfully then why doesn’t it submit on submission
I'm unable to understand when its get complied successfully then why doesn't it submit on submission
hi @utkarsh.gupta0311
refer
#include <bits/stdc++.h>
using namespace std;
// Function to print Next Greater Element for each element of the array
void nextGreater(int arr[], int n)
{
// Write Code here
stack<int> s;
int res[n];
for (int i = n - 1; i >= 0; i--) {
/* if stack is not empty, then
pop an element from stack.
If the popped element is smaller
than next, then
a) print the pair
b) keep popping while elements are
smaller and stack is not empty */
if (!s.empty()) {
while (!s.empty() && s.top() <= arr[i]) {
s.pop();
}
}
res[i] = s.empty() ? -1 : s.top();
s.push(arr[i]);
}
for (int i = 0; i < n; i++)
cout << arr[i] << "," << res[i] << endl;
}
// The Main Function
int main()
{
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int arr[n];
for(int i=0; i<n; i++){
cin>>arr[i];
}
nextGreater(arr, n);
}
return 0;
}
sir my code is also same but my code is more descriptive … i want you to tell mistake in my code plzz sir
if there is some mistake in my code then tell me that otherwise i’m not seeing any other code
hi @utkarsh.gupta0311 u dont have to just see u can refer from this to correct yours, this will develop the debugging habit
sir, i’m unable to correct my code since yesterday… that’s why i’m asking for help
if u can tell mistake in my code … it will boost my confidence only
@talhashamim001 sir i have done some formatting in my code my 3 test cases got passed but 2 test cases got stuck… please tell mistake in that only… my code is correct i know it is having some minor mistake please check and help me
hi @utkarsh.gupta0311 buddy u need to replace the space with comma here
cout << arr[i] << "," << v[i] << endl;
, u should try to develop these habits as in main test these are helpful
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.