Simplest C++ solution


#1

vector Solution::nextGreater(vector &arr) {
int n=arr.size();
int next, i, j; vector B;
for (i = 0; i < n; i++)
{
next = -1;
for (j = i + 1; j < n; j++)
{
if (arr[j] > arr[i])
{
next = arr[j];
break;
}
}
B.push_back(next);
}
return B;
}