fork download
  1. vi l(n, -1), r(n, n);
  2. stack<int> s;
  3. for (int i = 0; i < n; i++)
  4. {
  5. // Write reverse of what condtion you need
  6. while (s.size() && arr[s.top()] >= arr[i])
  7. {
  8. s.pop();
  9. }
  10.  
  11. // Now arr[s.top()] < arr[i] --> Next smaller element found for arr[i] !!
  12. if (s.size())
  13. {
  14. l[i] = s.top();
  15. }
  16. s.push(i);
  17. }
  18.  
  19. while (s.size())
  20. {
  21. s.pop();
  22. }
  23.  
  24. for (int i = n - 1; i >= 0; i--)
  25. {
  26. while (s.size() && arr[s.top()] >= arr[i])
  27. {
  28. s.pop();
  29. }
  30.  
  31. if (s.size())
  32. {
  33. r[i] = s.top();
  34. }
  35. s.push(i);
  36. }
  37.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:1: error: ‘vi’ does not name a type; did you mean ‘void’?
 vi l(n, -1), r(n, n);
 ^~
 void
prog.cpp:2:1: error: ‘stack’ does not name a type
 stack<int> s;
 ^~~~~
prog.cpp:3:1: error: expected unqualified-id before ‘for’
 for (int i = 0; i < n; i++)
 ^~~
prog.cpp:3:17: error: ‘i’ does not name a type
 for (int i = 0; i < n; i++)
                 ^
prog.cpp:3:24: error: ‘i’ does not name a type
 for (int i = 0; i < n; i++)
                        ^
prog.cpp:19:1: error: expected unqualified-id before ‘while’
 while (s.size())
 ^~~~~
prog.cpp:24:1: error: expected unqualified-id before ‘for’
 for (int i = n - 1; i >= 0; i--)
 ^~~
prog.cpp:24:21: error: ‘i’ does not name a type
 for (int i = n - 1; i >= 0; i--)
                     ^
prog.cpp:24:29: error: ‘i’ does not name a type
 for (int i = n - 1; i >= 0; i--)
                             ^
stdout
Standard output is empty