for {9,7,8} it gives me {8,8,-1}...not correct
On Jan 31, 11:16 am, abhijith reddy <[email protected]> wrote:
> simple dp
>
> void solve(int *arr,int sz)
> {
> int ans[sz];
> ans[sz-1]=-1;
> for(int i=sz-2;i>=0;i--)
> {
> if(arr[i]<arr[i+1]) ans[i]=arr[i+1];
> else ans[i]=ans[i+1];
> }
> for(int i=0;i<sz;i++)
> printf("%d ",ans[i]);
>
>
>
> }
> On Sun, Jan 30, 2011 at 10:00 PM, ritu <[email protected]> wrote:
> > You are given an array (unsorted) and for every element i, find the
> > first occurance of an element j (in the remaining array) that is
> > greater than or equal to i. If no such j occurs then print -1.
> > Eg: Input---> A={1,3,5,7,6,4,8}
> > Output---> 3 5 7 8 8 8 -1
> > Time Complexity:O(n)
> > Space Complexity:O(n)
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<algogeeks%2Bunsubscribe@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.- Hide quoted text -
>
> - Show quoted text -
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.