6 2 6 6 -1 s//6,2 min=6 ========================================================== https://www.naukri.com/code360/problems/least-greater-element_1164266?leftPanelTabValue=SUBMISSION import java.util.* ; import java.io.*; public class Solution { public static int[] leastGreaterElement(int[] arr) { // Write your code here ArrayList al=new ArrayList<>(); Stack s=new Stack<>(); int min=Integer.MAX_VALUE; boolean found=false; for(int i=arr.length-1;i>=0;i--){ found=false; min=Integer.MAX_VALUE; int x=arr[i]; for(Integer k:s){ if(x stack=new Stack<>(); boolean found=false; for(int i=0;i0){ if(stack.peek()>Math.abs(x)){ break; }else if(stack.peek()0 || stack.peek()<0){ stack.push(x); } } } int c=0; int ans[]=new int[stack.size()]; for(Integer i:stack){ ans[c]=i; c++; } return ans; } } ================================================================= [5,10,-20] first process each and every number previous numbers are there in the stack //5, 10 , //5 ,-20 -90 23 ============================================================= https://leetcode.com/problems/sum-of-subarray-minimums/