We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 47688da commit 6e5ea10Copy full SHA for 6e5ea10
Stack_Interview Problem/Next Smaller Left.java
@@ -0,0 +1,28 @@
1
+https://practice.geeksforgeeks.org/problems/help-classmates--141631/1?utm_source=gfg&utm_medium=article&utm_campaign=bottom_sticky_on_article
2
+
3
+class Solution{
4
+ static List<Integer> leftSmaller(int n, int arr[])
5
+ {
6
+ //Lets Play with Stack::
7
+ List<Integer> res = new ArrayList<>();
8
+ Stack<Integer> st = new Stack<>();
9
+ for(int i=0;i<n;i++){
10
+ if(st.isEmpty()){
11
+ res.add(-1);
12
+ }else if(st.peek()<arr[i]){
13
+ res.add(st.peek());
14
+ }else{
15
+ while(!st.isEmpty() && st.peek()>=arr[i]){
16
+ st.pop();
17
+ }
18
19
20
21
22
23
24
+ st.push(arr[i]);
25
26
+ return res;
27
28
+}
0 commit comments