@shady : yes i guess this is what question says:- so acc to this below algo work , i didnt execute it but i guess it will work
void nextSmaller(int arr[],int n) { s1 s; int i,next,ele; s.top=-1; push(&s,0); for(i=1;i<n;i++) { next=arr[i]; if(isEmpty(&s)) { ele=pop(&s); while(arr[ele] > next) { swap(arr,ele,i); next=arr[ele]; if(isEmpty(&s)==0) { break; } ele=pop(&s); } if(ele > next) { push(&s,ele); } } push(&s,i); } } On Sun, Mar 25, 2012 at 4:36 PM, shady <sinv...@gmail.com> wrote: > @gene > i think for 3 4 2 you need to start from left most element, and then make > substitutions one by one. > so it will be > 3 4 2 > 2 4 3 > 2 3 4 > > > @all i googled a bit, and found that O(n) solution is possible for it, any > idea ? > > On Sun, Mar 25, 2012 at 1:59 PM, Kartik Sachan <kartik.sac...@gmail.com>wrote: > >> +1 @saurabh...:P >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.